Given a tree, for each node , compute the sum of distances from to all other nodes. Distance = number of edges. Example: Tree with edges .
Answer: . Node has the smallest sum () because it's most central. With naive BFS from each node, you'd get . Let's solve it in with rerooting. Before reading the solution, try to identify the base case and recursive relationship yourself.