Data Structures & AlgorithmsHardCodeforces Div2 D · ICPC regional

A rooted tree has these parent→child edges: 38→80, 87→88, 88→70, 88→85, 56→91, 91→30, 87→38, 70→56. Each node starts with the value: 30=10, 38=17, 56=15, 70=10, 80=20, 85=4, 87=13, 88=4, 91=7. These updates are applied in order: set node 91 to 8; set node 91 to 18; set node 80 to 6; set node 85 to 16. Afterwards, what is the sum of the values in the subtree of node 88 (node 88 and all its descendants)?

  1. A. 50
  2. B. 30
  3. C. 109
  4. D. 73

Correct answer: D. 73

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