Data Structures & AlgorithmsVery hardCodeforces Div2 D · ICPC regional

A rooted tree has these parent→child edges: 71→93, 41→21, 41→16, 38→39, 45→96, 96→51, 38→45, 45→79, 93→94, 51→41, 79→71. 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 38, let tout be the largest tin inside its subtree (its own included). Give the pair [tin, tout] for node 38.

  1. A. [1, 13]
  2. B. [0, 11]
  3. C. [1, 12]
  4. D. [1, 11]

Correct answer: C. [1, 12]

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