Data Structures & AlgorithmsModerateCodeforces Div2 D · ICPC regional

A rooted tree has these parent→child edges: 21→56, 69→25, 56→69, 25→28, 25→14, 56→10. Each node starts with the value: 10=2, 14=4, 21=2, 25=4, 28=18, 56=4, 69=10. These updates are applied in order: set node 21 to 2; set node 28 to 11; set node 14 to 19; set node 25 to 11; set node 69 to 14. Afterwards, what is the sum of the values in the subtree of node 56 (node 56 and all its descendants)?

  1. A. 42
  2. B. 20
  3. C. 61
  4. D. 63

Correct answer: C. 61

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