Data Structures & AlgorithmsHardCodeforces Div 2 C · GATE CS
An undirected connected graph on 5 vertices has the edges (weights in brackets, all distinct): V–H (5), V–D (15), V–X (10), X–D (26), V–Z (16), H–Z (3), H–D (24), H–X (14). 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. 47
- B. 33
- C. 37
- D. 42
Correct answer: C. 37
The minimum spanning tree weighs 33. Among the other spanning trees the smallest total is 37, 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 47.
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
- Each cell of a grid with 5 rows and 3 columns has an arrow: R = right, L = left, U = up, D = down. ULR UUD ULL LUL UDU From a cell you may…
- A grid has 3 rows and 4 columns with these values (top to bottom): 1912 3838 7521 A path moves between side-adjacent cells (up, down, left…
- A directed graph with no directed cycles has arcs u→v (weight) : K→Q (2), K→N (-3), K→I (8), J→L (3), J→I (8), Q→N (7), Q→L (6), N→L (0)…
- A directed graph has the vertices A, D, J, N, P, V and the arcs N→V, N→P, N→A, V→A, D→A, P→A, A→V, A→D, A→J. How many strongly connected…
- Bellman–Ford is run from source M on the directed graph whose arcs (weights in brackets) are listed in the order they are relaxed: G→D…
- A grid has 5 rows and 6 columns (top to bottom; '.' open, '#' blocked): ...... .##.#. ...... ....#. ...... You may only move right or…