Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2 B
The directed acyclic graph has the vertices E, H, J, K, S, T, V, W and the arcs W→E, S→K, J→H, V→H, J→K, V→W, W→K, E→H, J→T, T→E, V→S, V→E, J→E, W→S. How many distinct directed paths go from V to K? A path is a sequence of consecutive arcs; a single arc counts as a path.
- A. 2
- B. 3
- C. 4
- D. 5
Correct answer: B. 3
Count with ways[x] = sum of ways[y] over arcs y→x, starting at ways[V] = 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
- Grid with 3 rows and 3 columns (top to bottom). A cell marked G is a gate; '.' is a normal cell: .GG G.. ... Each step, which is a move to…
- A directed acyclic graph has the vertices M, Q, U, V, X, Y, Z and the arcs M→Y, M→Q, M→V, U→Y, U→Z, U→V, Y→Q, Y→Z, Y→V, Q→Z, Q→X, Z→X…
- A bipartite graph has left side P1, P2, P3 and right side Q1, Q2, Q3, Q4, Q5, with edges P3–Q2, P2–Q4, P1–Q5, P3–Q4, P2–Q1, P3–Q5. What is…
- A flow network has source S and sink T, with directed arcs and capacities in brackets: S→A (9), D→T (3), A→D (1), A→T (4), B→D (4), B→T…
- A directed acyclic graph has the vertices D, G, K, L, Q, S, V, Y and the directed edges D→K, D→Q, D→L, D→V, Q→L, G→L, D→Y, Y→Q, K→Y, K→V…
- A tree has vertices F, G, J, K, L, M, N, U, X and weighted edges (weights in brackets): N–F (4), N–U (3), U–M (7), N–X (7), U–J (7), U–K…