You are given a tree T = (V, E) along with a designated root node r ∈ V. The parent of any node v ≠ r, denoted p(v), is defined to be the node adjacent to v in the path from r to v. By convention, p(r) = r. For k > 1, define
pk(v) = pk-1 (p(v)) and p1 (v) = p(v) (so pk(v) is the kth ancestor of v).
Each vertex v of the tree has an associated non-negative integer label l (v). Give a linear-time algorithm to update the labels of all the vertices in T according to the following rule: lnew(v) = l(pl(v)(v)).
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.