Data Structures & AlgorithmsHardCodeforces Div 2 D · ICPC regional
The directed acyclic graph has the vertices A, Q, T, V, W, Z and the arcs A→T, Z→Q, A→Q, W→T, Q→T, V→T, Z→V, A→V, V→Q. How many distinct directed paths go from Z to T? 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: A. 3
Count with ways[x] = sum of ways[y] over arcs y→x, starting at ways[Z] = 1 and processing vertices in a topological order. This gives 3 paths; using only paths of at most two arcs would give 2.
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
- Two unmarked jugs hold 3 litres and 7 litres. Allowed operations: fill a jug completely, empty a jug completely, or pour one jug into the…
- 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…
- 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…