Data Structures & AlgorithmsModerateCodeforces Div2 D · ICPC regional

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

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

Correct answer: A. [6, 6]

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