Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
A tree on the vertices C, F, I, R, V, X has the arcs C→R, V→C, I→V, V→X, F→V (each undirected edge is directed as shown). You may reverse the direction of some arcs. What is the minimum number of arcs to reverse so that every vertex can be reached from R?
- A. 1
- B. 5
- C. 2
- D. 4
Correct answer: D. 4
In a tree, each edge must point from the parent towards the child (away from the root); an edge pointing towards the root must be reversed. Brute force over reversal sets confirms 4. Counting the arcs that already point away gives 1, which is the wrong quantity.
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 directed acyclic graph has the vertices A, E, F, H, N, Q, R and the edges Q→N, Q→H, A→N, A→F, N→R, N→F, H→R, H→A, H→E. A topological…
- A directed acyclic graph has the vertices K, L, P, U, W, X, Y and the directed edges Y→W, Y→K, K→L, K→X, P→K, U→X, W→X, W→P, U→P, U→K…
- A tree has the vertices B, D, K, O, Q, V, W, Y, Z and the edges D–K, K–W, W–V, D–B, W–Q, V–Y, V–Z, Q–O. A set D dominates the tree if…
- Each cell of a grid with 3 rows and 5 columns has an arrow: R = right, L = left, U = up, D = down. RDLLR UUDUR LDUDD From a cell you may…
- A directed graph with no directed cycles has arcs u→v (weight) : U→A (-3), U→V (4), A→Z (3), V→O (2), Z→O (5). Weights may be negative…
- A directed acyclic graph has the vertices C, D, G, J, O, S, T and the directed edges D→J, G→C, G→O, S→O, C→J, D→O, O→J, D→T, C→O, S→C…