Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2 B
A tree on the vertices C, F, H, L, P, V, W has the arcs V→P, F→P, P→C, F→H, V→L, W→H (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 V?
- A. 3
- B. 4
- C. 2
- D. 6
Correct answer: C. 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
- Each cell of a grid with 3 rows and 4 columns has an arrow: R = right, L = left, U = up, D = down. RRLL URUU RRUD From a cell you may move…
- A counter starts at 1. Each step, you may add 1, add 2, or double the counter. Each step must stay at or below 18. Two sequences of steps…
- A pile holds p stones. In one move a player removes exactly s stones, where s is one of {2, 3, 4} and s ≤ the pile size. The player who…
- A connected undirected graph has the vertices B, F, K, N, U, W and weighted edges (weights in brackets): F–U (13), F–N (4), N–U (17), B–W…
- An undirected connected graph on 5 vertices has the edges (weights in brackets, all distinct): Y–K (11), S–K (2), Q–D (10), D–K (14), Y–S…
- A tree has vertices with values in brackets: N[-2], J[9], M[1], R[0], H[9], G[6], S[-2]. The edges are N–J, J–M, N–R, M–H, N–G, J–S. A…