Data Structures & AlgorithmsHardCodeforces Div2 D · ICPC regional

A rooted tree has these parent→child edges: 29→86, 49→48, 70→15, 49→71, 48→70, 49→12, 48→29, 71→72. Each node starts with the value: 12=16, 15=10, 29=5, 48=20, 49=9, 70=16, 71=11, 72=8, 86=17. These updates are applied in order: set node 15 to 19; set node 70 to 16; set node 71 to 13. Afterwards, what is the sum of the values in the subtree of node 70 (node 70 and all its descendants)?

  1. A. 35
  2. B. 26
  3. C. 77
  4. D. 19

Correct answer: A. 35

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