I was looking attempting the problem CNTTREE from SPOJ, but I am completely clueless on how to solve such problems. I don’t even understood the sample test case.

This problem is also there on codechef, I looked at the editorial but appeared very overwhelming.

Can anyone please explain how to solve this problem, with the background of such problems.