Data Structures & AlgorithmsHardCodeforces Div 2 · ICPC regional
Complete undirected graph on vertices A to F with symmetric edge weights given row by row (row i, column j = weight of edge between vertices i and j, with A = row 0): 0 8 7 14 14 8; 8 0 2 14 4 10; 7 2 0 10 10 13; 14 14 10 0 13 11; 14 4 10 13 0 12; 8 10 13 11 12 0. A tour visits every vertex exactly once and returns to the start. What is the minimum total weight of such a tour?
- A. 53
- B. 45
- C. 50
- D. 75
Correct answer: B. 45
Brute force over all 120 orders of the remaining vertices gives a minimum of 45. The greedy nearest-neighbour tour gives 50, and the largest tour weight 75 is a maximisation mistake.
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
- Bipartite graph with left side {A, B, C, D}, right side {E, F, G, H} and edges A–E, B–E, B–H, C–E, C–F, C–G, C–H, D–E. What is the size of…
- Distinct words ['bbba', 'aaa', 'bcaa', 'aac', 'b'] are inserted into an empty trie (one node per character, shared prefixes sharing nodes…
- A binary tree with distinct letters has preorder ACDEBF and inorder DEBCAF. What is its postorder traversal (left, right, root), written…
- Directed weighted graph on vertices B, F, A, C, D (source B, target D) with edges: B→F (2); B→A (5); A→F (-4); F→D (1); A→D (3); B→D (12)…
- Distinct words ['cc', 'aab', 'a', 'cbc', 'bbb', 'bc'] are inserted into an empty trie (one node per character, shared prefixes share…
- Directed weighted graph on vertices F, E, D, B, C (source F, target C) with edges: F→E (5); F→D (8); D→E (-5); E→C (1); D→C (6); F→C (8)…