编程题:最小生成树MST(Kruskal's or Prim's Algorithm)
Kruskal's algorithm is an algorithm in graph theory that finds a minimum spanning tree for a connected undirected weighted graph.
### Input Specifcation:
There are two numbers(n, m) in first line, n means how many points are there, and m means how many edges are there(n<1000, m<2000), there are m lines following the first line, there are three numbers(x ,y and c) in each line, x and y mean the points in one edge, and c is the weights of the edge.
### Output Specifcation:
The total weights of the minimum spanning tree.
### Input Example:
in
5 5
1 2 1
2 3 1
3 4 2
4 5 1
5 1 1
### Output Example:
out
4
答案:若无答案欢迎评论
### Input Specifcation:
There are two numbers(n, m) in first line, n means how many points are there, and m means how many edges are there(n<1000, m<2000), there are m lines following the first line, there are three numbers(x ,y and c) in each line, x and y mean the points in one edge, and c is the weights of the edge.
### Output Specifcation:
The total weights of the minimum spanning tree.
### Input Example:
in
5 5
1 2 1
2 3 1
3 4 2
4 5 1
5 1 1
### Output Example:
out
4
答案:若无答案欢迎评论