An MST Problem
View as PDFGiven nodes and
weighed bidirectional edges, build the Minimum Spanning Tree of the graph.
Input Specification
The first line will contain two integers
.
The next lines will each contain three integers,
.
Output Specification
Print the sum of the edges in the minimum spanning tree on the first line. If no minimum spanning tree can be built using the edges, print
0.
Sample Input
4 7
1 2 1
1 3 1
1 4 5
1 2 10
1 1 3
3 4 2
2 4 7
Sample Output
4
Comments