Godfather-Codewars

https://www.codechef.com/viewsolution/32400570
Can someone please help me in finding what’s the error in the above code that leads to TLE? The same code using LCA gets accepted and I think both have the same complexity.