Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div2 D
A rooted tree has these parent→child edges: 33→62, 48→67, 15→81, 48→77, 62→46, 67→83, 77→59, 59→68, 14→25, 50→33, 33→14, 51→15, 15→50, 67→51, 83→18. The parent of a node is its 1st ancestor. Using binary lifting, which node is the 4th ancestor of node 33?
- A. 51
- B. 67
- C. 48
- D. 50
Correct answer: B. 67
The 4th ancestor is reached by 4 parent steps from 33; binary lifting takes the bits of 4 as jumps. Off by one in the step count, or treating 4 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: 5→46, 73→89, 73→49, 72→21, 24→73, 46→11, 47→97, 11→24, 21→25, 72→18, 49→94, 5→72, 25→54…
- A rooted tree has these parent→child edges: 51→28, 59→94, 24→37, 26→59, 24→13, 2→99, 48→24, 64→16, 59→48, 24→2, 26→51, 37→64, 48→83. The…
- 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…
- 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…