Minimum Cost To Connect All Cities

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.
Input Format
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 Format
print the minimum cost.
Question Video
Constraints
1<= n <= 1000
1<= e <= n*(n-1)/2
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


  • Asked in Companies
  • Related Topics






Video Solution

Code Solution

Run
 
Run
Id Name