Data Structures & AlgorithmsHardICPC regional · Codeforces Div2 D

A rooted tree has these parent→child edges: 10→9, 81→72, 97→16, 85→10, 81→45, 73→40, 6→37, 9→6, 97→81, 45→73, 73→85, 37→30. The parent of a node is its 1st ancestor. Using binary lifting, which node is the 8th ancestor of node 30?

  1. A. 45
  2. B. 97
  3. C. 37
  4. D. 81

Correct answer: D. 81

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic