Data Structures & AlgorithmsVery hardCodeforces Div2 D · ICPC regional

A rooted tree has these parent→child edges: 69→68, 99→18, 69→36, 71→14, 68→71, 23→32, 59→9, 36→99, 18→13, 23→69, 14→34, 87→59, 87→93, 69→87. 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 69, let tout be the largest tin inside its subtree (its own included). Give the pair [tin, tout] for node 69.

  1. A. [3, 15]
  2. B. [3, 16]
  3. C. [2, 14]
  4. D. [3, 14]

Correct answer: A. [3, 15]

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