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?
- A. 63
- B. 30
- C. 37
- 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.
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
- An undirected connected graph on the vertices D, U, W, X has the edges U–X, D–W, D–X, W–X, D–U. How many spanning trees does it have? (A…
- A connected undirected graph has the vertices B, M, R, T, U and the edges U–T, U–M, U–R, T–R, T–B, M–B, R–B. Parallel edges are allowed…
- An undirected graph has the vertices A, D, F, P, U, Y and the edges P–A, Y–A, D–A, D–U, Y–F, D–F, P–F, U–A, Y–D, F–U. What is the minimum…
- A directed acyclic graph has the vertices D, L, P, Q, R, U, V and the edges V→R, Q→R, U→R, U→Q, U→D, U→P, L→Q. A topological order lists…
- Consider this recursive function: python def f(n): if n <= 0: return f(n - 2) if n % 3 == 0: f(n - 2) How many times is f called in total…
- A counter starts at 1. Each step, you may add 1, add 2, or double the counter. Each step must stay at or below 22. Two sequences of steps…