简单的高级实现
按值排序边缘,如果不创建循环,则按排序顺序将每个边缘添加到 MST。
algorithm kruskalMST(G: a graph)
sort G's edges by their value
MST = an empty graph
for each edge e in G:
if adding e to MST does not create a cycle:
add e to MST
return MST