![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
并查集
呆呆与笨笨
梦想是被追逐的,而不是幻想的
展开
-
hdu 1232 畅通工程(并查集)
#include int pre[1010]; int find(int x){ if(x==pre[x]) return x; else pre[x]=find(pre[x]); return pre[x]; }//查询 ,即查找集合的代表元素(查找树根) //路径压缩采用递归的方法(递归实现简洁、常见) void join(int x,int y){ int原创 2014-03-01 17:00:09 · 591 阅读 · 2 评论 -
并查集原理
http://wenku.baidu.com/view/7ed5c917866fb84ae45c8da5.html 讲的很不错的!!!原创 2014-03-01 17:02:46 · 664 阅读 · 0 评论 -
hdu 1272 小希的迷宫
1. 判断是否成环; 2. 判断是否只有一棵树; 3.0 0 也要输出Yes#include #include int father[100010],s; int vis[100010]; int find(int x){ if(x==father[x]) return x; else father[x]=find(father[x]); return father[x];原创 2014-03-01 17:56:02 · 567 阅读 · 1 评论 -
hdu 1213 How Many Tables(并查集)
#include #include #include using namespace std; int num[1010]; int find(int x){//找父节点 if(x==num[x]) return x; else num[x]=find(num[x]); //压缩路径 return num[x]; } void join(int x,int y){//合并 int f原创 2014-08-06 21:02:59 · 350 阅读 · 0 评论