Data Structures & AlgorithmsHardCodeforces Div 2 D · ICPC regional
Cities B, C, F, T, U are joined by roads with these travel costs: B–U 20, B–T 13, B–C 7, B–F 17, U–T 4, U–C 9, U–F 2, T–C 11, T–F 6, C–F 18. 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. 24
- B. 70
- C. 22
- D. 37
Correct answer: D. 37
Bitmask DP over subsets gives the minimum Hamiltonian cycle cost 37. A greedy nearest-neighbour tour costs 37, and an open path (no return leg) can be cheaper at 24.
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 tree has vertices with weights in brackets: E[6], C[8], O[8], B[11], X[14], D[9], T[5], M[1]. The edges are E–C, C–O, E–B, B–X, X–D…
- Bellman–Ford is run from source O on the directed graph whose arcs (weights in brackets) are listed in the order they are relaxed: L→O…
- Cities C, F, G, N, Q, X are joined by roads with these travel costs: C–Q 20, C–X 13, C–N 2, C–F 11, C–G 6, Q–X 8, Q–N 15, Q–F 13, Q–G 12…
- An undirected graph has the vertices J, M, N, Q, R, S, W and the edges R–N, M–Q, Q–J, Q–W, M–S, M–R, Q–R, Q–S, M–J, R–S. How many simple…
- A connected undirected graph has the vertices B, D, I, N, O, P, Z and the edges I–P, I–B, I–Z, I–N, P–N, P–O, B–D, Z–N. How many bridges…
- An undirected connected graph on 6 vertices has the edges (weights in brackets, all distinct): U–O (17), F–O (26), O–P (18), U–V (10), F–P…