Data Structures & AlgorithmsHardCodeforces Div2 D · ICPC regional
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 value: 6=11, 15=2, 29=12, 32=16, 47=1, 50=2, 57=14, 63=5, 66=14, 87=1, 88=3. These updates are applied in order: set node 29 to 14; set node 29 to 4; set node 47 to 14; set node 66 to 17; set node 57 to 9. Afterwards, what is the sum of the values in the subtree of node 6 (node 6 and all its descendants)?
- A. 25
- B. 44
- C. 17
- D. 28
Correct answer: D. 28
Apply the updates first, then sum the current values over the whole subtree of 6. 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: 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…
- 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…
- 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…