Data Structures & AlgorithmsHardCodeforces Div2 D · ICPC regional

A rooted tree has these parent→child edges: 54→25, 54→82, 25→34, 69→52, 25→60, 34→69, 54→88, 60→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 82, let tout be the largest tin inside its subtree (its own included). Give the pair [tin, tout] for node 82.

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

Correct answer: A. [8, 8]

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