Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2 B

Cities M, R, T, V, W are joined by roads with these travel costs: W–M 7, W–R 14, W–V 12, W–T 8, M–R 19, M–V 20, M–T 5, R–V 15, R–T 13, V–T 15. 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. 53
  2. B. 64
  3. C. 37
  4. D. 52

Correct answer: D. 52

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic