Minimum Cost To Connect All Cities
easy
There are n cities and there are roads in between some of the cities. Somehow all the roads are damaged simultaneously. We have to repair the roads to connect the cities again. There is a fixed cost to repair a particular road. Find out the minimum cost to connect all the cities by repairing roads.
Constraints
1<= n <= 1000 1<= e <= n*(n-1)/2
Format
Input
First line contains number of cities. Second line contains number of edges roads. Each of next E lines contain 3 number u and v and c denoting a road between u and v with cost c to repair.
Output
print the minimum cost.
Example
Sample Input
7
8
0 1 10
1 2 10
2 3 10
0 3 40
3 4 2
4 5 3
5 6 3
4 6 8
Sample Output
38