Data Structures & AlgorithmsHardCodeforces Div 2 D · ICPC regional
The directed acyclic graph has the vertices D, O, R, T, U, Y and the arcs Y→O, T→O, O→R, Y→T, Y→D, Y→R, T→R, T→U. How many distinct directed paths go from Y to R? A path is a sequence of consecutive arcs; a single arc counts as a path.
- A. 3
- B. 4
- C. 5
- D. 2
Correct answer: B. 4
Count with ways[x] = sum of ways[y] over arcs y→x, starting at ways[Y] = 1 and processing vertices in a topological order. This gives 4 paths; using only paths of at most two arcs would give 3.
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 connected undirected graph has the vertices B, F, M, O, Z and weighted edges (weights in brackets): O–M (16), F–Z (14), B–M (7), O–B…
- An undirected graph has the vertices C, J, L, Q, W and the edges W–L, J–C, L–C, J–Q, Q–L, W–C, W–J, W–Q. How many simple cycles does it…
- 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…
- 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…