Data Structures & AlgorithmsModerateCodeforces Div2 D · ICPC regional

A rooted tree has these parent→child edges: 37→60, 68→66, 37→80, 80→58, 80→23, 80→10, 68→37. Each node starts with the value: 10=12, 23=1, 37=18, 58=18, 60=6, 66=10, 68=17, 80=3. These updates are applied in order: set node 68 to 14; set node 80 to 9; set node 23 to 18. Afterwards, what is the sum of the values in the subtree of node 80 (node 80 and all its descendants)?

  1. A. 57
  2. B. 34
  3. C. 81
  4. D. 48

Correct answer: A. 57

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