Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

A directed graph has the vertices A, E, J, M and the arcs M→E, M→J, M→A, E→A, J→M, J→A, A→M, A→E, A→J. 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.

  1. A. 12
  2. B. 6
  3. C. 8
  4. D. 1

Correct answer: C. 8

A bitmask DP over (visited set, last vertex) counts directed Hamiltonian paths: 8 in total. Restricting to paths that start at M gives 2, and counting closed Hamiltonian cycles through M gives 1.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic