Data Structures & AlgorithmsHardICPC regional · Codeforces Div2 D

A rooted tree has these parent→child edges: 56→19, 30→85, 84→92, 56→64, 77→56, 66→77, 92→66, 77→30, 84→31, 64→32. The parent of a node is its 1st ancestor. Using binary lifting, which node is the 5th ancestor of node 32?

  1. A. 92
  2. B. 66
  3. C. 84
  4. D. 64

Correct answer: A. 92

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic