Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div2 D

A rooted tree has these parent→child edges: 72→20, 30→9, 81→90, 14→34, 20→48, 94→93, 90→53, 47→74, 48→30, 9→26, 26→14, 47→18, 34→94, 54→72, 34→81, 9→47, 54→22. The parent of a node is its 1st ancestor. Using binary lifting, which node is the 7th ancestor of node 90?

  1. A. 30
  2. B. 20
  3. C. 48
  4. D. 14

Correct answer: C. 48

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic