Data Structures & AlgorithmsModerateCodeforces Div2 D · ICPC regional
A rooted tree has these parent→child edges: 68→18, 76→82, 76→34, 82→68, 70→39, 82→70, 34→29, 70→17. 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 39, let tout be the largest tin inside its subtree (its own included). Give the pair [tin, tout] for node 39.
- A. [9, 10]
- B. [9, 9]
- C. [8, 8]
- D. [4, 4]
Correct answer: B. [9, 9]
tin of 39 is 9 and the subtree ends at entry 9, so the interval is [9, 9]. 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: 99→14, 99→52, 14→20, 14→16, 52→95, 99→53, 20→84. A DFS starts at the root and visits the…
- A rooted tree has these parent→child edges: 62→97, 33→7, 33→17, 62→10, 10→88, 10→35, 62→33, 88→2, 7→16. A DFS starts at the root and…
- A rooted tree has these parent→child edges: 75→17, 34→75, 75→45, 56→43, 43→14, 69→56, 43→34, 34→36. A DFS starts at the root and visits…
- 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…
- 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…