Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
A tree on the vertices J, L, M, N, T has the arcs T→J, J→N, L→T, M→T (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 J?
- A. 1
- B. 4
- C. 3
- D. 2
Correct answer: C. 3
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 3. 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 grid has 5 rows and 8 columns (rows listed top to bottom; '.' is an open cell, '#' a wall): ..#..... ....#..# ...#...# #.#..... ......#…
- An undirected graph on 5 vertices has the edges T–X, X–L, X–B, L–B, L–N, B–N. How many simple paths (no repeated vertex) go from T to N?…
- An undirected graph has the vertices D, E, H, J, M, P and the edges P–E, P–H, P–J, E–H, E–D, M–J, M–D. In how many ways can each vertex be…
- An undirected graph has the vertices A, B, F, I, J, P and the edges I–A, I–J, I–B, A–P, A–F, J–P, J–F, P–B. In how many ways can each…
- A directed acyclic graph has the vertices A, E, K, L, M, N and the directed edges L→A, K→N, E→K, L→E, M→N, L→K, M→E, E→N, L→N. How many…
- A directed weighted graph has the arcs u→v (weight): J→I (6), I→J (1), I→R (3), I→B (5), Q→I (2), Q→E (4), R→J (12), R→I (10), R→Q (2)…