Pick node as the arbitrary root. Run DFS. For each node , compute down[v] = the answer for the subtree rooted at . This uses standard tree DP. This is tree DP. You combine answers from all children of to get down[v]. The recurrence depends on the problem. For sum of distances, you add child contributions plus edge costs. After this pass, you know down[1] = the answer when node is root.
But you still need answers for all other roots. That is what the second pass does.