Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2 B

An undirected connected graph on 5 vertices has the edges (weights in brackets, all distinct): J–I (26), C–W (25), X–W (27), I–W (24), I–X (4), J–W (23), C–J (29). A spanning tree is a set of n − 1 edges with no cycle. What is the weight of the second-smallest spanning tree, meaning the smallest total weight that is strictly larger than the minimum spanning tree weight?

  1. A. 76
  2. B. 78
  3. C. 102
  4. D. 105

Correct answer: B. 78

The minimum spanning tree weighs 76. Among the other spanning trees the smallest total is 78, obtained by one exchange of an MST edge for a non-tree edge. Adding the cheapest non-tree edge to the MST without the exchange gives 102.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic