Data Structures & AlgorithmsHardCodeforces Div2 D · ICPC regional

A rooted tree has these parent→child edges: 85→36, 85→46, 18→93, 46→92, 56→18, 85→83, 36→56, 36→19. Each node starts with the value: 18=2, 19=2, 36=7, 46=11, 56=6, 83=5, 85=4, 92=19, 93=9. These updates are applied in order: set node 93 to 1; set node 92 to 7; set node 93 to 13; set node 18 to 2. Afterwards, what is the sum of the values in the subtree of node 36 (node 36 and all its descendants)?

  1. A. 26
  2. B. 30
  3. C. 15
  4. D. 57

Correct answer: B. 30

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