Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2 B

Cities A, B, N, T, U are joined by roads with these travel costs: A–N 15, A–U 2, A–B 4, A–T 14, N–U 17, N–B 5, N–T 13, U–B 8, U–T 6, B–T 9. 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. 63
  2. B. 30
  3. C. 37
  4. D. 17

Correct answer: B. 30

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic