Data Structures & AlgorithmsHardCodeforces Div 2 · ICPC regional
Points A(4,3), B(7,5), C(8,9), D(6,6), E(4,6) in the plane. The cost of joining two points is the Manhattan distance |x1−x2| + |y1−y2|. What is the minimum total cost of joining all points so that every point is connected to every other (minimum spanning tree)?
- A. 23
- B. 14
- C. 12
- D. 10
Correct answer: C. 12
Prim or Kruskal on these complete Manhattan distances gives 12. Connecting everything to one hub costs 23, and summing each point's nearest neighbour is not a spanning tree either.
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 trie keeps a counter at each node, and every word of the list W = ['bb', 'bba', 'aabc', 'ac', 'aba', 'bbc', 'aab', 'ac'] is inserted…
- Directed graph on vertices A, B, C, D, E, F with edges E→F, E→A, C→D, D→C, D→B, B→C, A→C, A→D, B→D (no weights). What is the number of…
- A binary tree with distinct letters has preorder CHEGDBFA and inorder HECFBADG. What is its postorder traversal (left, right, root)…
- Directed graph on vertices A, B, C, D, E, F, G with edges G→E, A→D, F→A, G→F, C→E, B→E, A→B, B→G, E→G, A→C (no weights). What is the…
- Coins of denominations [12, 11, 5, 3] are available in unlimited quantity. What is the minimum number of coins needed to pay exactly 34?…
- Array A = [7, 13, 13, 9, 9, 3, 1, 11]. Over all non-empty contiguous subarrays, what is the maximum value of the XOR of the elements in…