Data Structures & AlgorithmsVery hardCodeforces Div 2 C · GATE CS
An undirected connected graph on 5 vertices has the edges (weights in brackets, all distinct): A–F (17), S–P (22), F–P (29), A–P (10), A–S (21), N–F (20), N–P (6), N–S (23). 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?
- A. 74
- B. 54
- C. 83
- D. 55
Correct answer: D. 55
The minimum spanning tree weighs 54. Among the other spanning trees the smallest total is 55, 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 74.
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
- An undirected graph has the vertices D, M, P, Q, Y and the edges Q–P, Q–D, P–M, P–Y, M–D. A walk may repeat vertices and edges. How many…
- Starting from the integer 6, one operation either adds 1, subtracts 1, or doubles the current value. Values may be any non-negative…
- A tree has the vertices E, F, G, I, K, N, Y and the edges G–F, G–N, F–E, N–K, K–Y, K–I. A centroid is a vertex whose removal leaves no…
- An undirected graph on 7 vertices has the edges J–P, J–O, J–U, P–O, P–B, P–U, O–S, O–A, O–U, A–U. How many simple paths (no repeated…
- Grid with 4 rows and 4 columns (top to bottom). A cell marked G is a gate; '.' is a normal cell: .G.. G.G. .... .... Each step, which is a…
- A flow network has source S and sink T, with directed arcs and capacities in brackets: S→E (6), S→A (2), S→C (2), S→T (6), E→T (2), D→A…