Road Reparation
There are cities and
roads between them. Unfortunately, the condition of the roads is so poor that they cannot be used. Your task is to repair some of the roads so that there will be a decent route between any two cities.
For each road, you know its reparation cost, and you should find a solution where the total cost is as small as possible.
Input Specification
The first input line has two integers and
: the number of cities and roads. The cities are numbered
.
Then, there are m lines describing the roads. Each line has three integers ,
and
: there is a road between cities
and
, and its reparation cost is
. All roads are two-way roads.
Every road is between two different cities, and there is at most one road between two cities.
Output Specification
Print one integer: the minimum total reparation cost. However, if there are no solutions, print IMPOSSIBLE
.
Constraints
Sample Input
5 6
1 2 3
2 3 5
2 4 2
3 4 8
5 1 7
5 4 4
Sample Output
14
Comments