Data Structures & AlgorithmsHardCodeforces Div2 D · ICPC regional

A rooted tree has these parent→child edges: 6→67, 6→45, 6→4, 90→21, 90→65, 4→86, 7→90, 45→17, 6→7, 86→19. 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 4, let tout be the largest tin inside its subtree (its own included). Give the pair [tin, tout] for node 4.

  1. A. [2, 5]
  2. B. [1, 3]
  3. C. [9, 11]
  4. D. [2, 4]

Correct answer: D. [2, 4]

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