CHOCOLA - Is this a question of trees?

SPOJ.com - Problem CHOCOLA this problem is in Trees category of A2OJ, can someone suggest me a tree solution to this problem?