Data Structures & AlgorithmsHardCodeforces Div2 D · ICPC regional
A rooted tree has these parent→child edges: 71→4, 81→15, 81→74, 81→31, 4→81, 15→39, 15→30, 71→5. Each node starts with the value: 4=18, 5=20, 15=10, 30=4, 31=2, 39=18, 71=11, 74=18, 81=14. These updates are applied in order: set node 81 to 7; set node 39 to 16; set node 4 to 15; set node 30 to 7. Afterwards, what is the sum of the values in the subtree of node 15 (node 15 and all its descendants)?
- A. 33
- B. 32
- C. 60
- D. 23
Correct answer: A. 33
Apply the updates first, then sum the current values over the whole subtree of 15. Summing the old values, only the children, or the parent's subtree are the traps.
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: 93→74, 59→15, 74→59, 65→30, 16→45, 65→25, 73→33, 59→16, 74→73, 93→63, 65→28, 93→65. Each node…
- A rooted tree has these parent→child edges: 71→44, 29→79, 6→29, 46→40, 6→80, 69→83, 36→46, 80→16, 44→8, 29→69, 8→36, 29→71, 16→52. Each…
- A rooted tree has these parent→child edges: 20→84, 28→1, 72→74, 59→69, 99→20, 28→99, 14→47, 74→28, 30→59, 12→64, 72→12, 74→30, 69→14. Each…
- A rooted tree has these parent→child edges: 65→8, 60→61, 61→19, 61→57, 57→63, 72→65, 57→72, 19→83, 60→92, 8→82, 57→67, 60→13. Each node…
- A rooted tree has these parent→child edges: 78→10, 58→4, 90→37, 90→58, 91→85, 97→30, 30→31, 31→87, 87→55, 87→78, 97→90, 30→91, 97→98. Each…
- A rooted tree has these parent→child edges: 81→45, 81→61, 33→46, 78→51, 94→70, 46→81, 46→94, 94→58, 81→78, 58→72, 51→52. Each node starts…