Data Structures & AlgorithmsVery hardCodeforces Div2 D · ICPC regional

A rooted tree has these parent→child edges: 91→25, 57→40, 74→57, 37→24, 62→42, 37→14, 14→74, 40→62, 37→32, 37→91, 42→19, 35→37, 14→23, 25→16. A DFS starts at the root and visits the children of each node in increasing order of label. A global counter starts at 0 and is increased when a node is first entered; tin is the counter value at entry. For node 35, let tout be the largest tin inside its subtree (its own included). Give the pair [tin, tout] for node 35.

  1. A. [1, 16]
  2. B. [1, 15]
  3. C. [0, 14]
  4. D. [1, 14]

Correct answer: B. [1, 15]

tin of 35 is 1 and the subtree ends at entry 15, so the interval is [1, 15]. Reversing the child order changes the numbers, and an exclusive end or a 0-based start shifts them.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic