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

PROGRAMMING:Communication network design

Luz5年前 (2021-05-10)题库555
Suppose you are a telecommunication engineer, and you need to set up a communication network between villages, so that any two villages can achieve communication connectivity (but there is not necessarily a direct fast line connection, as long as there is an indirect line connection). The existing planning information data lists all the possible two villages and their line costs. Please judge whether the village interconnection can be realized. If so, what is the lowest cost of the whole network? If we can't realize village to village interconnection, which villages are divided into several parts?
###Input format:
The first line gives the number of villages n (1 ≤ n ≤ 50) and the number of candidate routes m ≥ 0; In the following M lines, each line gives three positive integers, which are the number of the two villages directly connected by the line (the number starts from 1) and the construction cost of the line.
###Output format:
Output the judgment result of whether to realize the village interconnection.
If it is, then output the lowest cost of the whole network.
If the interconnection cannot be realized, the output is divided into several parts and the villages in each part. The vertex of each unconnected part is from small to large. The order of each part is also listed from small to large according to the first vertex.
###Input example:
Here is a set of inputs. For example:
```in
6 10
1 2 6
1 5 10
1 6 12
2 4 5
2 6 8
2 3 3
3 4 7
4 5 9
4 6 11
5 6 16
```
###Output example:
The corresponding output is given here. For example:
```out
YES!
Total cost:31
```
###Input sample 2:
Here is a set of inputs. For example:
```in
5 4
1 2 3
1 3 11
2 3 8
4 5 9
```
###Output sample 2:
The corresponding output is given here. For example:
```out
NO!
one part:1 2 three
two part:4 5
```







answer:If there is no answer, please comment