Data Structures & AlgorithmsVery hardCodeforces Div2 D · ICPC regional

A rooted tree has these parent→child edges: 81→45, 81→61, 33→46, 78→51, 94→70, 46→81, 46→94, 94→58, 81→78, 58→72, 51→52. Each node starts with the value: 33=8, 45=11, 46=7, 51=14, 52=6, 58=13, 61=19, 70=8, 72=10, 78=17, 81=10, 94=8. These updates are applied in order: set node 72 to 18; set node 52 to 18; set node 33 to 17; set node 81 to 14; set node 72 to 10. Afterwards, what is the sum of the values in the subtree of node 78 (node 78 and all its descendants)?

  1. A. 37
  2. B. 31
  3. C. 49
  4. D. 93

Correct answer: C. 49

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