并查集
lkbsbird
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Poj 2524 Ubiquitous Religions
题意:简单并查集 解析:统计不同信仰的学生,标记即可#include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int maxn=50009; int student[maxn]; int n,m; int find(int x) { if(student[x]!=x) retu原创 2016-06-30 10:45:24 · 265 阅读 · 0 评论 -
并查集(1)
1.并查集主要包含两个功能:1)find功能:查找最上一级,也就是每一个节点对应的最上面的那个根节点 定义一个数组pre[],该数组的功能就是存储当前节点的上一级,初始化时:每一个节点的上一级就是本身 即:pre[1]=1,pre[2]=2,pre[3]=3...... int find(int x)//查找x的最上一级(路径压缩等会再介绍) { int r=x;//委托给r去找X的最上一级 whi原创 2016-07-01 18:27:09 · 281 阅读 · 0 评论 -
并查集(2)
并查集的另外形式: const int maxn=1999; typedef struct { int parent; int cnt; }node; node data[maxn]; void init() { for(int i=0;i { data[i].parent=i; data[i].cnt=1; } } int原创 2016-07-01 18:28:19 · 201 阅读 · 0 评论
分享