Fools and Roads
HardRating 1900CodeforcesAdvanced Trees (BST, LCA, Tree DP)
Approach hintTry it first, then revealHide
For each path (a, b), add 1 at a and at b and subtract 2 at their LCA. After summing these marks over subtrees, the value at a vertex is the number of paths using the edge to its parent.