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?
- A. 53
- B. 64
- C. 37
- 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.
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
- A directed acyclic graph has the vertices J, K, L, Q, R, S, X, Y and the directed edges S→R, S→Y, K→Y, L→K, R→Q, Y→X, K→X, J→Q, Y→J, J→X…
- Consider this recursive function: python def f(n): if n <= 0: return f(n - 1) if n % 2 == 0: f(n - 2) How many times is f called in total…
- Floyd–Warshall runs on vertices 1 to 4 with these arcs u→v (weight): 1→2 (4), 1→3 (8), 1→4 (4), 2→1 (5), 2→4 (2), 3→1 (6), 3→2 (5), 3→4…
- Floyd–Warshall runs on vertices 1 to 4 with these arcs u→v (weight): 1→2 (3), 1→4 (9), 2→3 (6), 2→4 (10), 3→1 (12), 3→2 (6), 4→1 (12), 4→2…
- A tree has the vertices F, H, L, N, O, T, U, V, X and the edges L–O, O–F, L–N, F–H, L–V, O–X, H–U, F–T. A centroid is a vertex whose…
- An undirected graph has the vertices E, F, G, I, Z and the edges G–I, G–Z, G–F, E–F, I–Z, I–F, Z–F. A walk may repeat vertices and edges…