#P3366. 【模板】最小生成树
【模板】最小生成树
Description
As stated, given an undirected graph, compute a minimum spanning tree. If the graph is disconnected, output orz.
Input Format
The first line contains two integers , representing that the graph has nodes and undirected edges. Then each of the next lines contains three integers , indicating there is an undirected edge of length connecting nodes and .
Output Format
If the graph is connected, output a single integer equal to the sum of the edge lengths in the minimum spanning tree. If the graph is disconnected, output orz.
4 5
1 2 2
1 3 2
1 4 3
2 3 4
3 4 3
7
Hint
Constraints:
- For 20% of the testdata, , .
- For 40% of the testdata, , .
- For 70% of the testdata, , .
- For 100% of the testdata, , , , .
Sample explanation:

Therefore, the total edge weight of the minimum spanning tree is .
Translated by ChatGPT 5
京公网安备 11011102002149号