[JAVA] Getting RE error. But sample test case passes

Even for smaller inputs im getting RE error. But when i run locally with the same inputs its giving me the correct answer.
Problem: TreeEdge
My Solution: link
Codechef submission: https://www.codechef.com/viewsolution/34466684
Can anyone please help me find out the issue.

May I ask what MAX_DEPTH is for and why it is only 20? Try a test case with n>20, I think that will fail.