Data Structures & AlgorithmsHardCodeforces Div 2 C · GATE CS
A tree on the vertices B, C, D, H, J, T, Z has the arcs T→B, Z→T, B→C, B→D, J→D, J→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 T?
- A. 2
- B. 3
- C. 4
- D. 6
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
- A grid has 4 rows and 4 columns with these values (top to bottom): 9446 8699 5398 3165 A path moves between side-adjacent cells (up, down…
- Floyd–Warshall runs on vertices 1 to 5 with these arcs u→v (weight): 1→2 (4), 1→3 (2), 2→1 (11), 3→1 (8), 3→2 (4), 3→4 (7), 3→5 (4), 4→1…
- Bellman–Ford is run from source U on the directed graph whose arcs (weights in brackets) are listed in the order they are relaxed: K→U…
- A four-wheel combination lock shows four digits 0–9 on wheels that wrap around (9 goes to 0 and 0 goes to 9). One move turns one wheel by…
- A tree has vertices with weights in brackets: D[15], C[15], R[7], L[9], S[1], Z[3], B[13], H[13], F[6]. The edges are D–C, D–R, R–L, D–S…
- 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…