Data Structures & AlgorithmsHardCodeforces Div2 D · ICPC regional
A rooted tree has these parent→child edges: 30→84, 43→48, 28→43, 30→95, 28→22, 30→9, 87→89, 9→28, 37→65, 37→87, 37→30. 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 9, let tout be the largest tin inside its subtree (its own included). Give the pair [tin, tout] for node 9.
- A. [3, 8]
- B. [3, 7]
- C. [2, 6]
- D. [8, 12]
Correct answer: B. [3, 7]
tin of 9 is 3 and the subtree ends at entry 7, so the interval is [3, 7]. Reversing the child order changes the numbers, and an exclusive end or a 0-based start shifts them.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- A rooted tree has these parent→child edges: 74→47, 37→3, 47→65, 47→9, 66→38, 38→74, 9→89, 89→45, 65→37. A DFS starts at the root and…
- 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…
- A rooted tree has these parent→child edges: 54→25, 54→82, 25→34, 69→52, 25→60, 34→69, 54→88, 60→30. A DFS starts at the root and visits…
- A rooted tree has these parent→child edges: 55→43, 55→71, 15→68, 19→95, 98→4, 71→98, 19→15, 71→19. A DFS starts at the root and visits the…
- A rooted tree has these parent→child edges: 27→82, 55→59, 27→68, 61→55, 28→22, 82→42, 27→28, 22→61, 27→51. A DFS starts at the root and…
- A rooted tree has these parent→child edges: 54→78, 95→12, 32→75, 32→82, 25→95, 95→9, 9→84, 32→68, 54→63, 68→54, 68→25. A DFS starts at the…