Data Structures & AlgorithmsHardCodeforces Div2 D · ICPC regional
A rooted tree has these parent→child edges: 85→36, 85→46, 18→93, 46→92, 56→18, 85→83, 36→56, 36→19. Each node starts with the value: 18=2, 19=2, 36=7, 46=11, 56=6, 83=5, 85=4, 92=19, 93=9. These updates are applied in order: set node 93 to 1; set node 92 to 7; set node 93 to 13; set node 18 to 2. Afterwards, what is the sum of the values in the subtree of node 36 (node 36 and all its descendants)?
- A. 26
- B. 30
- C. 15
- D. 57
Correct answer: B. 30
Apply the updates first, then sum the current values over the whole subtree of 36. 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: 6→46, 32→57, 46→40, 6→59, 98→51, 59→98, 98→48, 6→62, 32→90, 32→6. Each node starts with the…
- A rooted tree has these parent→child edges: 47→15, 50→87, 32→47, 32→88, 47→6, 6→66, 63→29, 50→63, 87→32, 87→57. Each node starts with the…
- A rooted tree has these parent→child edges: 54→83, 78→54, 80→72, 59→82, 55→25, 83→76, 80→59, 72→78, 82→55. Each node starts with the…
- A rooted tree has these parent→child edges: 94→5, 94→31, 76→21, 13→94, 94→76, 13→83, 31→68, 31→79. Each node starts with the value: 5=7…
- A rooted tree has these parent→child edges: 60→68, 9→73, 60→27, 60→1, 60→47, 47→26, 73→60. Each node starts with the value: 1=19, 9=10…
- A rooted tree has these parent→child edges: 49→95, 56→30, 49→71, 71→3, 59→62, 30→91, 91→11, 91→59, 49→56. Each node starts with the value…