最小生成树

最小生成树

Kruskal算法

//使用并查集,基本操作略

Quick_sort(1,m);     //对边按权值排序

For i:=1 to m do

Begin

  X:=father(e[i].a);

  Y:=father(e[i].b);

  If x<>y then

  Begin

Union(x,y);

Inc(k);

E[i].select:=true;

  End;

  If k=n-1 then break;

End;

posted @ 2015-05-05 12:49  no regrets  阅读(74)  评论(0编辑  收藏  举报