Data Structures & AlgorithmsHardCodeforces Div 2 D · ICPC regional
A tree on the vertices B, E, G, S, W has the arcs W→E, S→E, B→W, W→G (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 E?
- A. 3
- B. 1
- C. 2
- D. 4
Correct answer: A. 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
- The directed acyclic graph has the vertices C, F, G, K, N, T, W and the arcs C→F, W→C, G→N, G→K, N→F, K→F, T→W, W→F, T→F, G→T, K→C, T→K…
- A directed acyclic graph has the vertices B, I, M, Q, R and the arcs B→Q, B→R, I→Q, I→R, I→M, Q→M. Two players alternately move a single…
- Starting from the integer 15, one operation either adds 1, subtracts 1, or doubles the current value. Values may be any non-negative…
- A tree has vertices with weights in brackets: A[5], Z[10], I[13], N[7], L[8], M[15], D[8], R[12], C[9]. The edges are A–Z, Z–I, I–N, A–L…
- An undirected graph has the vertices B, I, L, N, Q, Y, Z and the edges N–L, N–Y, N–Q, N–I, N–Z, L–Y, L–Q, B–I, B–Z. What is its chromatic…
- An undirected graph has the vertices A, C, J, Q, S, Z and the edges S–C, S–J, S–A, Q–Z, C–J, A–Z. What is the size of a maximum matching…