Data Structures & AlgorithmsHardICPC regional · Codeforces Div2 D
A rooted tree has these parent→child edges: 97→81, 81→54, 69→17, 81→33, 46→69, 54→84, 17→94, 73→97, 69→76, 97→21, 94→73. The parent of a node is its 1st ancestor. Using binary lifting, which node is the 2nd ancestor of node 97?
- A. 73
- B. 94
- C. 17
- D. 46
Correct answer: B. 94
The 2nd ancestor is reached by 2 parent steps from 97; 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 rooted tree has these parent→child edges: 68→88, 79→50, 9→20, 41→51, 41→79, 88→6, 9→18, 50→95, 95→71, 50→68, 71→9. The parent of a node…
- A rooted tree has these parent→child edges: 54→40, 90→13, 40→63, 11→52, 13→84, 54→82, 11→67, 54→90, 63→57, 13→1, 54→15, 67→54. The parent…
- 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…
- 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…
- 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…