Data Structures & AlgorithmsHardCodeforces Div 2 D · ICPC regional
A directed graph has the vertices A, M, O, V and the arcs O→M, O→A, M→O, M→A, A→O, A→V, V→O, V→A. 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. 6
- B. 1
- C. 10
- D. 5
Correct answer: A. 6
A bitmask DP over (visited set, last vertex) counts directed Hamiltonian paths: 6 in total. Restricting to paths that start at O gives 1, and counting closed Hamiltonian cycles through O 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 B, D, E, F, I, M, X and the edges M–E, M–X, M–D, M–B, M–F, E–X, E–D, E–I, X–D, X–B, D–F, B–I, F–I…
- A directed weighted graph has the arcs u→v (weight): Y→K (14), Y→Q (6), K→L (4), K→T (5), L→Q (8), D→Y (3), D→Q (11), D→T (3), Q→Y (12)…
- Each cell of a grid with 3 rows and 4 columns has an arrow: R = right, L = left, U = up, D = down. UURD DLRU LRUU From a cell you may move…
- A grid has 3 rows and 4 columns with these values (top to bottom): 4179 9341 9892 A path moves between side-adjacent cells (up, down, left…
- Two unmarked jugs hold 4 litres and 5 litres. Allowed operations: fill a jug completely, empty a jug completely, or pour one jug into the…
- A directed graph has the vertices J, K, L, R, W and the arcs W→K, W→L, W→J, K→W, K→L, K→R, L→W, L→K, L→J, J→L, R→K, R→J. Count the…