-->
当前位置:首页 > 题库 > 正文内容

编程题:最小生成树MST(Kruskal's or Prim's Algorithm)

Luz3年前 (2021-12-31)题库943
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







答案:若无答案欢迎评论

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。