![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
并查集
君卿
这个作者很懒,什么都没留下…
展开
-
poj 2524 宗教 并查集
做并查集时,会出现让你求剩余多少(其他的都连在一个树上了)时是没有连的,或者总共有分成了几组这种类似的题,用单个时的个数N,每并一个,减一个剩余=(N-1)--;组数=N--;两个树并时,是树根并,不是父节点并,自己总搞错!!!#include<iostream>#include<algorithm>using namespace std;int fa[50005];voi...原创 2018-05-10 19:28:12 · 116 阅读 · 0 评论 -
畅通工程 并查集 一
#include<iostream>#include<cstdio> using namespace std;int fa[10010];int find(int x){ return fa[x]==x?x:(fa[x]=find(fa[x]));//路径压缩 ,使搜索过的直接接在树根上}void unite(int x,int y){ int a,b; a=find(x)...原创 2018-04-18 21:00:23 · 155 阅读 · 0 评论