Data Structures & AlgorithmsHardCodeforces Div2 D · ICPC regional

A rooted tree has these parent→child edges: 30→84, 43→48, 28→43, 30→95, 28→22, 30→9, 87→89, 9→28, 37→65, 37→87, 37→30. 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 9, let tout be the largest tin inside its subtree (its own included). Give the pair [tin, tout] for node 9.

  1. A. [3, 8]
  2. B. [3, 7]
  3. C. [2, 6]
  4. D. [8, 12]

Correct answer: B. [3, 7]

tin of 9 is 3 and the subtree ends at entry 7, so the interval is [3, 7]. 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