Data Structures & AlgorithmsModerateCodeforces Div2 D · ICPC regional

A rooted tree has these parent→child edges: 82→80, 31→89, 31→7, 5→31, 89→77, 5→82. Each node starts with the value: 5=13, 7=10, 31=10, 77=8, 80=15, 82=20, 89=9. These updates are applied in order: set node 7 to 18; set node 82 to 11; set node 77 to 6; set node 77 to 7; set node 7 to 7. Afterwards, what is the sum of the values in the subtree of node 82 (node 82 and all its descendants)?

  1. A. 35
  2. B. 26
  3. C. 72
  4. D. 15

Correct answer: B. 26

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