I am talking about the Problem COT2 on SPOJ. I am getting WA for this problem. I have been trying to get the error but i am unable to do so.Can anyone point out to any possible bug in my code. Thanks in advance.

Problem Link:- http://www.spoj.com/problems/COT2/ Solution Link:- https://ideone.com/0qRvNR

PS:- I had found a testcase which gave WA on spoj toolkit but the tree is too big so its not that helpful WA Testcase link:- https://ideone.com/elSPXG

Thanks.