#P1242B. 0-1 MST
0-1 MST
No submission language available for this problem.
Description
Ujan has a lot of useless stuff in his drawers, a considerable part of which are his math notebooks: it is time to sort them out. This time he found an old dusty graph theory notebook with a description of a graph.
It is an undirected weighted graph on vertices. It is a complete graph: each pair of vertices is connected by an edge. The weight of each edge is either or ; exactly edges have weight , and all others have weight .
Since Ujan doesn't really want to organize his notes, he decided to find the weight of the minimum spanning tree of the graph. (The weight of a spanning tree is the sum of all its edges.) Can you find the answer for Ujan so he stops procrastinating?
The first line of the input contains two integers and (, ), the number of vertices and the number of edges of weight in the graph.
The -th of the next lines contains two integers and (, ), the endpoints of the -th edge of weight .
It is guaranteed that no edge appears twice in the input.
Output a single integer, the weight of the minimum spanning tree of the graph.
Input
The first line of the input contains two integers and (, ), the number of vertices and the number of edges of weight in the graph.
The -th of the next lines contains two integers and (, ), the endpoints of the -th edge of weight .
It is guaranteed that no edge appears twice in the input.
Output
Output a single integer, the weight of the minimum spanning tree of the graph.
Samples
Note
The graph from the first sample is shown below. Dashed edges have weight , other edges have weight . One of the minimum spanning trees is highlighted in orange and has total weight .

In the second sample, all edges have weight so any spanning tree has total weight .