Data Structures & AlgorithmsHardCodeforces Div2 D · ICPC regional
A rooted tree has these parent→child edges: 38→80, 87→88, 88→70, 88→85, 56→91, 91→30, 87→38, 70→56. Each node starts with the value: 30=10, 38=17, 56=15, 70=10, 80=20, 85=4, 87=13, 88=4, 91=7. These updates are applied in order: set node 91 to 8; set node 91 to 18; set node 80 to 6; set node 85 to 16. Afterwards, what is the sum of the values in the subtree of node 88 (node 88 and all its descendants)?
- A. 50
- B. 30
- C. 109
- D. 73
Correct answer: D. 73
Apply the updates first, then sum the current values over the whole subtree of 88. 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: 29→86, 49→48, 70→15, 49→71, 48→70, 49→12, 48→29, 71→72. Each node starts with the value…
- 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…
- 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…