Data Structures & AlgorithmsHardCodeforces Div2 D · ICPC regional

A rooted tree has these parent→child edges: 6→46, 32→57, 46→40, 6→59, 98→51, 59→98, 98→48, 6→62, 32→90, 32→6. Each node starts with the value: 6=9, 32=9, 40=17, 46=15, 48=20, 51=6, 57=13, 59=8, 62=9, 90=7, 98=9. These updates are applied in order: set node 6 to 12; set node 46 to 12; set node 98 to 2; set node 46 to 13. Afterwards, what is the sum of the values in the subtree of node 59 (node 59 and all its descendants)?

  1. A. 43
  2. B. 10
  3. C. 36
  4. D. 87

Correct answer: C. 36

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