Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div2 D

A rooted tree has these parent→child edges: 85→81, 81→10, 82→79, 79→76, 85→82, 97→22, 76→5, 88→64, 64→43, 76→36, 1→90, 22→6, 6→88, 99→97, 5→1, 90→24, 79→99. The parent of a node is its 1st ancestor. Using binary lifting, which node is the 2nd ancestor of node 90?

  1. A. 1
  2. B. 5
  3. C. 76
  4. D. 79

Correct answer: B. 5

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