随笔分类 - 并查集
数据结构
摘要:P1536 村村通本题要求统计连通分块的个数,同一个连通分块可以用并查集进行处理 /* 村村通 */ #include<iostream> using namespace std; const int Max=1010; int pre[Max]; int n,m,cnt; void make()
阅读全文
摘要:P1621 集合 #include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #include<cstdlib> #include<cmath> #define maxn 100010 using namespa
阅读全文
摘要:P3367 【模板】并查集 #include<iostream> #include<algorithm> using namespace std; const int maxm=10010; int pre[maxm]; int n,m; void make()//初始化 { for (int i=
阅读全文
摘要:P1551 亲戚是一题经典的并查集的应用,有亲戚关系的为一个集合。 #include<iostream> using namespace std; const int maxn=5010; int pre[5010]; int n,m,p; void make()//初始化 { for (int i
阅读全文
摘要:并查集(Disjoint-Set)是一种可以动态维护若干个不重叠的集合,并支持合并与查询的数据结构。详细地说,并查集包括如下两个基本操作:1.Get,查询一个元素属于哪一个集合。2.Merge,把两个集合合并成一个大集合。为了具体实现并查集这种数据结构,我们首先需要定义集合的表示方法。在并查集中,我
阅读全文