首页 > 编程语言 > 详细

最小生成数(并查集)Kruskal算法

时间:2016-04-02 14:51:40      阅读:215      评论:0      收藏:0      [点我收藏+]
并查集:
使用并查集可以把每个连通分量看作一个集合,该集合包含连通分量的所有点。这两两连通而具体的连通方式无关紧要,
就好比集合中的元素没有先后顺序之分,只有属于和不属于的区别。
#define N 100 int father[N]; void init() { for(int i=0;i<n;i++) father[i]=1; } void union(int x,int y) //合并两元素所在集合 { x=getfather(x); y=getfather(y); if(x!=y) father[x]=y; } /*bool same(int x,int y) //判断两元素在不在同一集合 {return getfather(x)==getfather(y);} */ int getfather(int x) //获得该元素的父亲节点 { while(x!=father[x]) {x=father[x];} return x; }

 

最小生成数(并查集)Kruskal算法

原文:http://www.cnblogs.com/jin-nuo/p/5347531.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!