Modify an algorithm for computing the depth of each node so that it computes path lengths at the same time.