并查集 POj 2524
来源:互联网 发布:华为mate10知乎 编辑:程序博客网 时间:2024/06/06 05:48
题目点这里
题目大意
和上一篇HDU1213一样,最基本的并查集题目
代码
#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>const int M = 50005;int id[M];int count;int find(int p){ while(p != id[p]) p = id[p]; return p;}bool connected(int p,int q){ return find(p) == find(q);}void unionn(int p,int q){ int pRoot = find(p); int qRoot = find(q); if(pRoot == qRoot) return; id[pRoot] = qRoot; --count;}int main(){ int n,m; int ans = 0; while(scanf("%d%d",&n,&m)) { if(n == 0 && m == 0) break; count = n; for(int i = 1;i <= n; i++) id[i] = i; while(m--) { int p,q; scanf("%d%d",&p,&q); unionn(p,q); } printf("Case %d: %d\n",++ans,count); } return 0; }
0 0
- poj 2524 并查集
- 并查集 POJ 2524
- poj-2524 并查集
- poj 2524(并查集)
- POJ-2524 并查集
- poj 2524(并查集)
- POJ 2524 并查集
- POJ 2524 查并集
- POJ 2524 并查集
- POJ 2524 并查集
- poj 2524 并查集
- POJ 2524 并查集
- poj 2524[并查集]
- POJ 2524 (并查集)
- POJ 2524 并查集
- poj 2524 并查集
- 并查集 POj 2524
- POJ 2524 并查集
- 字符集与编码七之BOM
- Android探索之旅(第十三篇)AndroidStudio开发人员不得不知道的奇淫技巧(持续收录中......)
- Eclipse的黑色背景
- 博客搬家。
- 【模拟试题】完成工作
- 并查集 POj 2524
- 生成二维码和扫描二维码
- 【IMMVWeb训练营作业】使用Vue2.x生成简易的todoList
- supervisord
- Java详解匿名内部类
- SEM经验-4
- maven配置项目实例.
- 解决开启extension=php_curl.dll后curl扩展开启仍失败的问题
- 山寨币,虚拟币,和比特币的区块链技术有什么区别