Data Structures & AlgorithmsHardCodeforces Div2 D · ICPC regional

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, 26=18, 27=7, 47=16, 60=12, 68=13, 73=18. These updates are applied in order: set node 26 to 19; set node 26 to 17; set node 73 to 11. Afterwards, what is the sum of the values in the subtree of node 47 (node 47 and all its descendants)?

  1. A. 34
  2. B. 84
  3. C. 33
  4. D. 17

Correct answer: C. 33

Apply the updates first, then sum the current values over the whole subtree of 47. 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