Data Structures & AlgorithmsHardCodeforces Div2 D · ICPC regional

A rooted tree has these parent→child edges: 74→47, 37→3, 47→65, 47→9, 66→38, 38→74, 9→89, 89→45, 65→37. 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 3, let tout be the largest tin inside its subtree (its own included). Give the pair [tin, tout] for node 3.

  1. A. [10, 11]
  2. B. [9, 9]
  3. C. [10, 10]
  4. D. [7, 7]

Correct answer: C. [10, 10]

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