You are given a tree with nodes. For each node, calculate the sum of distances from that node to all other nodes. This is harder than Tree Distances I because sum is not max.
You cannot use diameter endpoints. This problem requires rerooting DP: compute the answer for root, then update incrementally when you move the root to each child. When you shift the root from parent to child, some nodes get closer and others get farther. Track subtree sizes to compute these shifts in per edge.