Sum of Distances in Tree
HardLeetCodeAdvanced Trees (BST, LCA, Tree DP)
Approach hintTry it first, then revealHide
Compute subtree sizes and the answer for one root. Moving the root to a child v brings size[v] nodes one step closer and the other n - size[v] one step further, so a second DFS yields every answer.