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)?

  1. A. 33
  2. B. 32
  3. C. 60
  4. 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.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic