Data Structures & AlgorithmsHardCodeforces Div 2 C · GATE CS
Cities E, P, U, V, Y are joined by roads with these travel costs: V–E 6, V–P 20, V–U 9, V–Y 20, E–P 2, E–U 20, E–Y 11, P–U 15, P–Y 11, U–Y 17. A salesman must visit every city exactly once and return to his starting city, minimising the total cost. What is the minimum total cost?
- A. 28
- B. 45
- C. 46
- D. 60
Correct answer: B. 45
Bitmask DP over subsets gives the minimum Hamiltonian cycle cost 45. A greedy nearest-neighbour tour costs 45, and an open path (no return leg) can be cheaper at 28.
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
- Consider this function: python def g(n): if n < 3: return n if n % 2 == 0: return g(n - 3) + g(n - 2) return g(n - 3) - 1 What value does…
- Grid with 4 rows and 4 columns (top to bottom). A cell marked G is a gate; '.' is a normal cell: ..GG ..G. .G.. ..G. Each step, which is a…
- An undirected graph has the vertices C, D, F, K, W, Y and the edges D–W, D–F, D–Y, D–K, W–Y, C–Y, C–K, F–Y, Y–K. What is its chromatic…
- A flow network has source S and sink T, with directed arcs and capacities in brackets: S→D (9), S→B (6), D→B (9), D→T (4), E→D (3), E→T…
- A flow network has source S and sink T, with directed arcs and capacities in brackets: S→B (7), S→T (6), A→B (5), A→T (3), E→B (2), B→C…
- Starting from the integer 3, one operation either adds 1, subtracts 1, or doubles the current value. Values may be any non-negative…