I am trying very hard but not able to get AC on single test case.
Solution Link: https://www.codechef.com/viewsolution/47363257
Approach: Go to each node and if it havn’t token then find the deepest node of that’s node subtree which has token, and store the difference b/w their depths.
I am using two dfs first one for calculating depth and flat the tree.
Second for traversing the subtree of each node.
Please help me