Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div2 D

A rooted tree has these parent→child edges: 71→93, 2→71, 23→92, 84→23, 79→86, 92→24, 92→35, 72→84, 86→72, 69→73, 69→40, 73→83, 40→34, 84→2, 69→79. The parent of a node is its 1st ancestor. Using binary lifting, which node is the 2nd ancestor of node 35?

  1. A. 92
  2. B. 84
  3. C. 86
  4. D. 23

Correct answer: D. 23

The 2nd ancestor is reached by 2 parent steps from 35; 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