Data Structures & AlgorithmsVery hardCodeforces Div2 D · ICPC regional
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 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 52, let tout be the largest tin inside its subtree (its own included). Give the pair [tin, tout] for node 52.
- A. [3, 7]
- B. [3, 6]
- C. [2, 5]
- D. [10, 13]
Correct answer: B. [3, 6]
tin of 52 is 3 and the subtree ends at entry 6, so the interval is [3, 6]. 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: 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…
- A rooted tree has these parent→child edges: 69→68, 99→18, 69→36, 71→14, 68→71, 23→32, 59→9, 36→99, 18→13, 23→69, 14→34, 87→59, 87→93…
- A rooted tree has these parent→child edges: 91→25, 57→40, 74→57, 37→24, 62→42, 37→14, 14→74, 40→62, 37→32, 37→91, 42→19, 35→37, 14→23…
- A rooted tree has these parent→child edges: 71→93, 41→21, 41→16, 38→39, 45→96, 96→51, 38→45, 45→79, 93→94, 51→41, 79→71. A DFS starts at…
- 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…