Data Structures & AlgorithmsVery hardCodeforces Div2 D · ICPC regional
A rooted tree has these parent→child edges: 44→19, 5→48, 4→60, 87→85, 19→5, 68→38, 48→4, 87→70, 19→78, 48→86, 70→56, 19→33, 38→87, 19→68. 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 5, let tout be the largest tin inside its subtree (its own included). Give the pair [tin, tout] for node 5.
- A. [3, 8]
- B. [2, 6]
- C. [11, 15]
- D. [3, 7]
Correct answer: D. [3, 7]
tin of 5 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: 37→60, 68→66, 37→80, 80→58, 80→23, 80→10, 68→37. Each node starts with the value: 10=12, 23=1…
- A rooted tree has these parent→child edges: 82→80, 31→89, 31→7, 5→31, 89→77, 5→82. Each node starts with the value: 5=13, 7=10, 31=10…
- A rooted tree has these parent→child edges: 21→56, 69→25, 56→69, 25→28, 25→14, 56→10. Each node starts with the value: 10=2, 14=4, 21=2…
- A rooted tree has these parent→child edges: 38→80, 87→88, 88→70, 88→85, 56→91, 91→30, 87→38, 70→56. Each node starts with the value…
- A rooted tree has these parent→child edges: 29→86, 49→48, 70→15, 49→71, 48→70, 49→12, 48→29, 71→72. Each node starts with the value…
- A rooted tree has these parent→child edges: 85→36, 85→46, 18→93, 46→92, 56→18, 85→83, 36→56, 36→19. Each node starts with the value: 18=2…