【POJ-2524】Ubiquitous Religions(并查集)
来源:互联网 发布:淘宝返利网是骗局吗 编辑:程序博客网 时间:2024/05/22 04:56
并查集。
#include<cstdio>#include<cstring>using namespace std;const int maxn = 55555;int fa[maxn];int vis[maxn];int n,m,t;void init(){ for(int i = 0; i < n; i++) {fa[i] = i;} memset(vis,0,sizeof(vis));}int find_father(int u){ return fa[u] == u ? u : fa[u] = find_father(fa[u]);}int main(){ int Case = 1; while(scanf("%d%d",&n,&m)){ if(!m && !n) break; init(); for(int i = 0; i < m; i++){ int x,y; scanf("%d%d",&x,&y); int fx = find_father(x); int fy = find_father(y); fa[fx] = fy; } int cnt = 0; for(int i = 1; i <= n; i++){ int t = find_father(i); if(!vis[t]){ vis[t] = 1; cnt ++; } } printf("Case %d: %d\n",Case++,cnt); } return 0;}
0 0
- POJ 2524 Ubiquitous Religions(并查集)
- POJ 2524-Ubiquitous Religions 并查集
- POJ 2524 Ubiquitous Religions 并查集
- poj 2524 Ubiquitous Religions(并查集)
- poj 2524 Ubiquitous Religions 并查集
- POJ 2524 Ubiquitous Religions (并查集)
- [poj 2524]Ubiquitous Religions[并查集]
- poj 2524 - Ubiquitous Religions(并查集)
- POJ 2524 Ubiquitous Religions (并查集)
- [并查集]POJ 2524 Ubiquitous Religions
- POJ 2524 Ubiquitous Religions 并查集
- poj 2524 Ubiquitous Religions --- 并查集
- POJ 2524 Ubiquitous Religions(并查集)
- POJ-2524 Ubiquitous Religions 并查集
- poj 2524 Ubiquitous Religions(并查集)
- poj 2524 Ubiquitous Religions(并查集)
- POJ 2524 Ubiquitous Religions (并查集)
- POJ 2524 Ubiquitous Religions 并查集
- 稀疏矩阵的运算(相乘,输出,转置,相加)
- 真机 模拟器 framework 终端合并
- 二分图大讲堂——彻底搞定最大匹配数(最小覆盖数)、最大独立数、最小路径覆盖、带权最优匹配(转)
- Word Break II
- Linux串口编程详解 linux串口相关设置函数
- 【POJ-2524】Ubiquitous Religions(并查集)
- nyoj860_又见01背包
- 修改文件扩展名,视频轻松传微云
- Java根据路径获取文件夹里的文件名
- 安卓判断网络连接 检查SD卡是否存在源码
- SQL中的单记录函数
- pig代码格式上小注意
- jquery对象与DOM对象
- 这是一个ibatIS xml文件