Data Structures & AlgorithmsVery hardCodeforces Div2 D · ICPC regional

A rooted tree has these parent→child edges: 65→8, 60→61, 61→19, 61→57, 57→63, 72→65, 57→72, 19→83, 60→92, 8→82, 57→67, 60→13. Each node starts with the value: 8=6, 13=17, 19=16, 57=17, 60=9, 61=10, 63=11, 65=12, 67=10, 72=16, 82=4, 83=1, 92=10. These updates are applied in order: set node 82 to 20; set node 63 to 16; set node 67 to 18; set node 19 to 8. Afterwards, what is the sum of the values in the subtree of node 72 (node 72 and all its descendants)?

  1. A. 54
  2. B. 38
  3. C. 28
  4. D. 105

Correct answer: A. 54

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