TLE in QTREE6

can anyone tell me why my code is giving TLE. Thankyou in advance…
link to solution http://www.codechef.com/viewsolution/3129993
problem link http://www.codechef.com/problems/QTREE6

I have changed my solution but getting WA this time…though i hv checked my program nearly for all testcases…can anyone tell me where my code is failing…Thankyou…solution link http://www.codechef.com/viewsolution/3131562

We would suggest you to go through the editorial of QTREE6 here: http://discuss.codechef.com/questions/31833/qtree6-editorial and post your doubts in the comment section. This will help you get over your doubt fast.