POJ 2524 Ubiquitous Religions (并查集 II)
来源:互联网 发布:js实现点击显示和隐藏 编辑:程序博客网 时间:2024/05/04 02:37
点击此处打开原题链接:http://poj.org/problem?id=2524
题目大意:
学校里所有人都信宗教,每个人只能信一种宗教。
输入n个人m组数,每组数代表2个人信的是一种宗教。
问学校里存在多少种宗教。
附AC源代码:
#include <stdio.h>#define M 50001int father[M],Array[M];int find (int x){if (father[x] != x) father[x] = find(father[x]);return father[x];} int main(int argc, char *argv[]){int n,m,a,b,i=0,index;while (scanf ("%d%d",&n,&m) != EOF){int sum = 0;if (n == 0 && m == 0) break;else { for (index =1; index <= n; ++index){ father[index] = index; Array[index] =0; }for (index =1; index <= m; ++index){scanf ("%d%d",&a,&b);a = find(a),b = find(b),father[a] = b;}for (index =1; index <= n; ++index){find(index);Array[father[index]] = 1;}for (index =1; index <= n; ++index)if (Array[index]) ++sum;printf ("Case %d: %d\n",++i,sum);}}return 0;}
- POJ 2524 Ubiquitous Religions (并查集 II)
- 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 (并查集)
- ubuntu加速
- ubuntu 英文环境下ibus的安装
- 学生信息管理
- “常量指针”和“指针常量”
- dispatch.s——MQX-Lite调度与中断系统的基础(1)
- POJ 2524 Ubiquitous Religions (并查集 II)
- 邻位互换法—全排列
- DVWA SQL Injection
- 算法2013110202
- c#截屏
- 提取中文字段的 缩写
- 简易版基于Java的处理静态资源服务器实现
- Troubleshoot Grid Infrastructure Startup Issues (Doc ID 1050908.1)
- iPhone跳转的动画效果类型及实现方法 CATransition