Data Structures & AlgorithmsHardCodeforces Div 2 C · GATE CS

Cities H, J, L, T, W are joined by roads with these travel costs: H–T 6, H–W 9, H–L 19, H–J 19, T–W 19, T–L 20, T–J 15, W–L 13, W–J 14, L–J 5. A salesman must visit every city exactly once and return to his starting city, minimising the total cost. What is the minimum total cost?

  1. A. 48
  2. B. 49
  3. C. 33
  4. D. 62

Correct answer: A. 48

Bitmask DP over subsets gives the minimum Hamiltonian cycle cost 48. A greedy nearest-neighbour tour costs 48, and an open path (no return leg) can be cheaper at 33.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic