So far we've solved problems with a fixed root. Now we need an answer for every node as if it were the root. This is where rerooting comes in.
For each node, compute the sum of distances to all other nodes. Computing this separately for each root would be . Rerooting gives us .
Think: If you know the answer for node u, how does the answer change when you move the root to a child v?