Data Structures & AlgorithmsHardCodeforces Div2 D · ICPC regional

A rooted tree has these parent→child edges: 93→68, 69→36, 1→26, 33→1, 14→94, 94→55, 69→33, 33→93, 14→52, 14→69, 36→82. 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 94, let tout be the largest tin inside its subtree (its own included). Give the pair [tin, tout] for node 94.

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

Correct answer: A. [11, 12]

tin of 94 is 11 and the subtree ends at entry 12, so the interval is [11, 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