Given a bidirectional, connected, weighted graph with nodes and edges, find the difference between the sum of the edges of the maximum and minimum spanning trees of the graph.
Constraints
Input Specification
The first line of input will contain space-separated integers and .
The next lines will contain space-separated integers , , and denoting an edge.
Output Specification
Output one integer, the difference between the sum of the edges of the maximum and minimum spanning trees.
Note: 64-bit integers may be required for this problem.
Sample Input
4 5
1 2 1
1 3 2
2 3 5
2 4 4
3 4 3
Sample Output
5
The graph given is shown in the above figure. The sum of the edges of the minimum spanning tree is using edges , , and (in the sample input). The sum of the edges of the maximum spanning tree is , using edges , , and . The difference is thus .
Comments