Data Structures & AlgorithmsVery hardCodeforces Div 2 D · ICPC regional
A tree on the vertices E, H, N, U, W, Z has the arcs H→N, N→Z, U→N, U→E, W→Z (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 H?
- A. 1
- B. 3
- C. 2
- D. 5
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 3, 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 graph with no directed cycles has arcs u→v (weight) : V→K (4), V→X (3), K→F (-1), K→X (-2), F→X (8), X→W (8). Weights may be…
- A counter starts at 1. Each step, you may add 1, add 2, or double the counter. Each step must stay at or below 19. Two sequences of steps…
- An undirected graph has the vertices D, M, R, V and the edges M–D, M–V, M–R, D–V, D–R, V–R. A walk may repeat vertices and edges. How many…
- The directed acyclic graph has the vertices A, B, C, G, J, O and the arcs J→C, G→C, J→O, J→A, G→A, J→B, B→C, O→B. How many distinct…
- A tree has vertices with weights in brackets: T[6], C[15], K[8], Z[3], U[2], V[2], N[14], G[14], F[1], H[7]. The edges are T–C, T–K, K–Z…
- The directed acyclic graph has the vertices D, E, J, L, N, Q, S, Z and the arcs D→Q, Z→N, N→Q, Q→S, D→J, E→S, L→Q, E→Q, D→N, E→N, J→Q…