-->
当前位置:首页 > 题库

PROGRAMMING:The road links every village

Luz5年前 (2021-05-10)题库508
In the statistical data table of the existing roads between villages, the cost of several roads that may be built into standard roads is listed, so as to obtain the minimum cost required for each village to have a road connection.
###Input format:
The input data include the positive integer number of towns $$n $$($$Le 1000 $$) and the number of candidate roads $$M $$($$Le 3N $$); The next $$M $$row corresponds to $$M $$roads. Each row gives three positive integers, which are the numbers of the two towns directly connected by the road and the estimated cost of the road reconstruction. For simplicity, towns are numbered from 1 to $$n $.
###Output format:
The lowest cost of exporting village to village communication. If the input data is not enough to ensure smooth traffic, the output $$- 1 $$, indicating that more roads need to be built.
###Input example:
```in
6 15
1 2 5
1 3 3
1 4 7
1 5 4
1 6 2
2 3 4
2 4 6
2 5 2
2 6 6
3 4 6
3 5 1
3 6 1
4 5 10
4 6 8
5 6 3
```
###Output example:
```out
twelve
```






answer:If there is no answer, please comment