UVa 10600 - ACM Contest and Blackout

10600 - ACM Contest and Blackout

 * http://acm.uva.es/p/v106/10600.html

Summary
Given a Graph, find the Minimum Spanning Tree and the second Minimum Spanning Tree.

Explanation
Find the Minimum Spanning Tree. ($$O(V^2)$$ implementation is fine.) Since the Minimum Spanning Tree algorithm is a Greedy algorithm, one of the second Minimum Spanning Tree should have nearly the same structure, if we were not so greedy on the edges. Note that in the Minimum Spanning Tree, there are V-1edges. We can bruteforce this by removing the edges of the Minimum Spanning Tree one at a time, and calculating the resultant Minimum Spanning Tree. The one with the minimum cost would be the second Minimum Spanning Tree. The total complexity is $$O(V^3)$$.

Input
Input Here

Output
Output Here