AdvancedRating 1700
Cheapest Network
Connect all n towns with cables 'u v cost' at minimum total cost (Kruskal). Print the cost, or -1 if impossible.
Input
n m, then m lines.
Output
A number.
Sample 1
Input
4 5 1 2 1 2 3 4 1 3 3 3 4 2 2 4 5
Output
6
Sample 2
Input
2 0
Output
-1
Output appears here