Hi everyone, I was trying to solve this problem. You can find my code here. My complexity is $$$O(N \cdot log^2(N))$$$.
However, I am getting TLE. Can someone please help in optimizing my code? I have written appropriate comments in the DFS function. For LCA and Centroid Decomposition, I referred to this blog and took the code from here.
Please help.