Data Structures & AlgorithmsHardICPC regional · Codeforces Div2 D

A rooted tree has these parent→child edges: 7→76, 73→25, 25→89, 89→95, 23→62, 76→79, 69→1, 7→73, 79→33, 1→41, 23→69, 1→7, 25→49. The parent of a node is its 1st ancestor. Using binary lifting, which node is the 2nd ancestor of node 95?

  1. A. 89
  2. B. 73
  3. C. 25
  4. D. 1

Correct answer: C. 25

The 2nd ancestor is reached by 2 parent steps from 95; binary lifting takes the bits of 2 as jumps. Off by one in the step count, or treating 2 as an absolute depth, gives the trap nodes.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic