Pass (down): Root at node . Compute = nodes in 's subtree, and = sum of distances from to all nodes in its subtree. and .
Pass (up): Starting from root, propagate answers to children using the formula from the previous unit.
The first pass collects information from leaves to root. The second pass distributes answers from root to leaves.