Data Structures & AlgorithmsHardCodeforces Div 2 C · GATE CS
A directed graph has the vertices A, D, E, I, U and the arcs E→A, E→I, A→E, A→D, D→E, D→I, D→U, I→A, U→E, U→A, U→D. 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. 9
- B. 10
- C. 15
- D. 1
Correct answer: B. 10
A bitmask DP over (visited set, last vertex) counts directed Hamiltonian paths: 10 in total. Restricting to paths that start at E gives 1, and counting closed Hamiltonian cycles through E 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
- An undirected graph has the vertices A, G, N, O, S and the edges O–N, G–S, S–O, S–A, A–N, A–O, S–N. How many simple cycles does it contain…
- A bipartite graph has left side P1, P2, P3 and right side Q1, Q2, Q3, Q4, Q5, with edges P2–Q2, P3–Q1, P2–Q1, P1–Q5, P1–Q4, P1–Q2. What is…
- An undirected connected graph on 5 vertices has the edges (weights in brackets, all distinct): B–H (11), B–I (7), C–H (30), E–I (16), B–C…
- A directed graph with no directed cycles has arcs u→v (weight) : U→C (-1), U→Z (6), U→H (8), U→K (8), C→Z (-2), C→H (-1), Z→H (5), Z→K…
- An undirected graph has the vertices C, D, F, L, U, X and the edges F–L, F–D, F–C, L–U, L–C, U–C, X–C. What is the size of a maximum…
- A directed weighted graph has the arcs u→v (weight): Q→H (15), Q→Y (9), H→Q (8), H→Y (3), H→E (13), B→Q (8), B→Y (2), B→E (4), Y→H (2)…