Data Structures & AlgorithmsHardICPC regional · Codeforces Div2 D

A rooted tree has these parent→child edges: 27→24, 99→40, 97→46, 81→87, 87→97, 81→27, 30→99, 24→51, 40→81. The parent of a node is its 1st ancestor. Using binary lifting, which node is the 3rd ancestor of node 27?

  1. A. 99
  2. B. 40
  3. C. 30
  4. D. 81

Correct answer: A. 99

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic