Data Structures & AlgorithmsModerateCodeforces Div 2 C · GATE CS
A tree on the vertices F, I, P, S, T, W, Z has the arcs W→T, T→Z, W→S, W→F, P→T, P→I (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 T?
- A. 2
- B. 4
- C. 6
- D. 3
Correct answer: A. 2
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 2. Counting the arcs that already point away gives 4, 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
- Bellman–Ford is run from source J on the directed graph whose arcs (weights in brackets) are listed in the order they are relaxed: C→J…
- Each cell of a grid with 3 rows and 3 columns has an arrow: R = right, L = left, U = up, D = down. ULU LUR ULU From a cell you may move to…
- A tree has vertices A, D, E, J, L, Q, T, W, X and weighted edges (weights in brackets): L–T (2), T–D (6), D–W (9), T–Q (6), Q–J (7), L–X…
- Each cell of a grid with 3 rows and 4 columns has an arrow: R = right, L = left, U = up, D = down. DLUL RUUR DLRD From a cell you may move…
- A directed graph with no directed cycles has arcs u→v (weight) : A→U (8), Z→U (1), Z→I (1), E→U (-2), E→I (2), U→C (4), U→I (5), C→I (-2)…
- A connected undirected graph has the vertices F, G, O, P, R, U, Y and the edges P–O, P–G, P–F, O–U, O–R, R–G, R–Y, Y–F. How many bridges…