Data Structures & AlgorithmsModerateCodeforces Div 2 D · ICPC regional
A directed graph has the vertices B, D, E, M, Y and the arcs B→M, B→E, B→D, B→Y, M→B, M→E, M→D, E→B, E→Y, D→B, D→M, D→E, D→Y, Y→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. 28
- C. 33
- D. 6
Correct answer: B. 28
A bitmask DP over (visited set, last vertex) counts directed Hamiltonian paths: 28 in total. Restricting to paths that start at B gives 6, and counting closed Hamiltonian cycles through B gives 4.
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 C, P, T, X and the edges T–P, C–P, C–X, P–X. In how many ways can each vertex be given one of 3…
- Cities B, C, F, T, U are joined by roads with these travel costs: B–U 20, B–T 13, B–C 7, B–F 17, U–T 4, U–C 9, U–F 2, T–C 11, T–F 6, C–F…
- A tree has vertices with weights in brackets: E[6], C[8], O[8], B[11], X[14], D[9], T[5], M[1]. The edges are E–C, C–O, E–B, B–X, X–D…
- Bellman–Ford is run from source O on the directed graph whose arcs (weights in brackets) are listed in the order they are relaxed: L→O…
- Cities C, F, G, N, Q, X are joined by roads with these travel costs: C–Q 20, C–X 13, C–N 2, C–F 11, C–G 6, Q–X 8, Q–N 15, Q–F 13, Q–G 12…
- An undirected graph has the vertices J, M, N, Q, R, S, W and the edges R–N, M–Q, Q–J, Q–W, M–S, M–R, Q–R, Q–S, M–J, R–S. How many simple…