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?
- A. 92
- B. 84
- C. 86
- 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.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- A tree has these parent→child edges, with positive weights: 63→18 (weight 3), 36→83 (weight 8), 91→79 (weight 2), 91→63 (weight 1), 79→36…
- A tree has these parent→child edges, with positive weights: 95→70 (weight 1), 70→51 (weight 2), 82→9 (weight 6), 51→82 (weight 5), 52→17…
- A tree has these parent→child edges, with positive weights: 54→92 (weight 5), 92→46 (weight 1), 8→41 (weight 7), 46→8 (weight 5), 54→3…
- A tree has these parent→child edges, with positive weights: 97→79 (weight 3), 19→93 (weight 8), 79→29 (weight 4), 26→97 (weight 5), 19→26…
- A tree has these parent→child edges, with positive weights: 95→29 (weight 6), 29→88 (weight 5), 59→75 (weight 6), 29→54 (weight 9), 98→25…
- A tree has these parent→child edges, with positive weights: 83→91 (weight 3), 19→73 (weight 1), 33→25 (weight 5), 91→1 (weight 5), 73→31…