Data Structures & AlgorithmsVery hardCodeforces Div2 D · ICPC regional

A rooted tree has these parent→child edges: 61→32, 20→75, 32→20, 50→88, 33→74, 33→3, 49→85, 7→33, 75→49, 32→50, 32→83, 36→7, 85→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 20, let tout be the largest tin inside its subtree (its own included). Give the pair [tin, tout] for node 20.

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

Correct answer: C. [3, 11]

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