Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div2 D
A rooted tree has these parent→child edges: 13→29, 25→79, 65→24, 86→96, 24→13, 13→51, 25→94, 86→25, 17→65, 2→17, 92→18, 93→86, 75→93, 79→92, 65→75. The parent of a node is its 1st ancestor. Using binary lifting, which node is the 3rd ancestor of node 96?
- A. 75
- B. 93
- C. 65
- D. 2
Correct answer: A. 75
The 3rd ancestor is reached by 3 parent steps from 96; 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.
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 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…
- 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…
- 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…
- 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…