POJ2524 Ubiquitous Religions
来源:互联网 发布:微博刷粉软件ios 编辑:程序博客网 时间:2024/05/19 02:27
#include <iostream>#include <cstdio>#include <vector>#include <algorithm>#include <cstring>#include <string>using namespace std;const int maxn = 50001;int f[maxn+10];int gn, gm;int getFather(int x) {if(x == f[x]) return x;else return f[x] = getFather(f[x]);}int main(){int Case = 0;int x, y, t1, t2;while(scanf("%d%d", &gn, &gm) == 2 && (gn || gm)) {for(int i = 1; i <= maxn; i++) f[i] = i;for(int j = 0; j < gm; j++) {scanf("%d%d", &x, &y);t1 = getFather(x);t2 = getFather(y);if(t1 != t2) f[t1] = t2;}int cnt = 0;for(int i = 1; i <= gn; i++) {if(f[i] == i) cnt++;}printf("Case %d: %d\n", ++Case, cnt);}}
0 0
- poj2524 Ubiquitous Religions
- Ubiquitous Religions POJ2524
- POJ2524 Ubiquitous Religions
- POJ2524:Ubiquitous Religions
- poj2524 Ubiquitous Religions
- poj2524 Ubiquitous Religions
- poj2524 Ubiquitous Religions
- POJ2524 Ubiquitous Religions
- poj2524 Ubiquitous Religions
- poj2524--Ubiquitous Religions
- POJ2524 Ubiquitous Religions
- POJ2524,Ubiquitous Religions
- poj2524--Ubiquitous Religions
- POJ2524--Ubiquitous Religions
- 【POJ2524】Ubiquitous Religions
- POJ2524 Ubiquitous Religions
- poj2524 Ubiquitous Religions
- poj2524 Ubiquitous Religions
- 【框架-MFC】 CView 渐变颜色采样值(1)
- 【PyQt实例4】设置文体排序和对齐【转】
- xml 转换conf 基于python
- .NET过滤html标签
- 【编程好习惯】利用编程语言特性提高程序执行效率
- POJ2524 Ubiquitous Religions
- hashmap和hashtable的区别
- oracle数据库 sql%found,sql%notfound,sql%rowcount
- 我是个爱改Bug的程序员
- hdu1232 畅通工程
- HTML学习笔记
- unp.h的使用
- 使用测试
- 交换机上的指示灯狂闪