Pick node as root. For each node , compute down[v] = sum of distances from to all nodes in its subtree. Also track size[v] = number of nodes in subtree of . Recurrence: down[v] = Σ_(u in children(v)) (down[u] + size[u]). The down[u] part is the sum within 's subtree. The +size[u] part accounts for the extra edge from to for each of the size[u] nodes. After this pass, down[1] equals the answer when node is root.
But you need answers for all other roots. That requires the up pass.