Data Structures & AlgorithmsVery hardCodeforces Div2 D · ICPC regional

A rooted tree has these parent→child edges: 71→44, 29→79, 6→29, 46→40, 6→80, 69→83, 36→46, 80→16, 44→8, 29→69, 8→36, 29→71, 16→52. Each node starts with the value: 6=18, 8=16, 16=12, 29=9, 36=12, 40=4, 44=10, 46=10, 52=16, 69=2, 71=8, 79=4, 80=17, 83=5. These updates are applied in order: set node 79 to 19; set node 79 to 15; set node 71 to 19. Afterwards, what is the sum of the values in the subtree of node 44 (node 44 and all its descendants)?

  1. A. 26
  2. B. 71
  3. C. 52
  4. D. 42

Correct answer: C. 52

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