Data Structures & AlgorithmsHardCodeforces Div 2 C · GATE CS
A directed graph has the vertices D, F, M, O, S and the arcs M→D, M→O, D→O, D→F, O→S, F→O, S→M. Count the directed Hamiltonian paths: sequences that list every vertex exactly once, where each consecutive pair is joined by an arc from the earlier to the later vertex. Sequences are counted over all possible starting vertices.
- A. 4
- B. 10
- C. 1
- D. 5
Correct answer: D. 5
A bitmask DP over (visited set, last vertex) counts directed Hamiltonian paths: 5 in total. Restricting to paths that start at M gives 1, and counting closed Hamiltonian cycles through M gives 1.
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
- On an 7×7 chessboard, rows and columns are numbered 0 to 6, and squares are written (row, column). A knight moves in the usual L-shape…
- A directed acyclic graph has the vertices A, F, J, K, P, R, S and the edges P→A, P→F, A→F, J→F, J→S, J→R, S→F. A topological order lists…
- A counter starts at 1. Each step, you may add 1, add 2, or double the counter. Each step must stay at or below 23. Two sequences of steps…
- Bellman–Ford is run from source S on the directed graph whose arcs (weights in brackets) are listed in the order they are relaxed: S→E…
- Cities J, O, Q, V, X, Y are joined by roads with these travel costs: X–J 4, X–Q 5, X–Y 7, X–V 6, X–O 2, J–Q 8, J–Y 4, J–V 5, J–O 9, Q–Y…
- An undirected graph has the vertices C, E, F, L, U, X, Z and the edges L–C, C–U, X–L, E–C, Z–L, E–U, F–L, Z–C, E–Z, X–U. How many simple…