Data Structures & AlgorithmsHardCodeforces Div2 D · ICPC regional

A rooted tree has these parent→child edges: 75→17, 34→75, 75→45, 56→43, 43→14, 69→56, 43→34, 34→36. 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 75, let tout be the largest tin inside its subtree (its own included). Give the pair [tin, tout] for node 75.

  1. A. [7, 9]
  2. B. [7, 10]
  3. C. [6, 8]
  4. D. [5, 7]

Correct answer: A. [7, 9]

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