Data Structures & AlgorithmsHardCodeforces Div2 D · ICPC regional
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 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 19, let tout be the largest tin inside its subtree (its own included). Give the pair [tin, tout] for node 19.
- A. [4, 8]
- B. [4, 7]
- C. [3, 6]
- D. [5, 8]
Correct answer: B. [4, 7]
tin of 19 is 4 and the subtree ends at entry 7, so the interval is [4, 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: 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…
- A rooted tree has these parent→child edges: 93→68, 69→36, 1→26, 33→1, 14→94, 94→55, 69→33, 33→93, 14→52, 14→69, 36→82. A DFS starts at the…
- A rooted tree has these parent→child edges: 69→64, 89→27, 15→69, 23→7, 24→15, 23→82, 23→94, 15→52, 1→89, 24→23, 52→1, 82→81. A DFS starts…
- A rooted tree has these parent→child edges: 61→32, 20→75, 32→20, 50→88, 33→74, 33→3, 49→85, 7→33, 75→49, 32→50, 32→83, 36→7, 85→36. A DFS…
- A rooted tree has these parent→child edges: 87→39, 39→15, 87→65, 49→67, 41→45, 45→91, 24→61, 15→72, 39→24, 24→81, 15→42, 61→49, 65→41. A…