POJ2524 Ubiquitous Religions
来源:互联网 发布:考上清华美院知乎 编辑:程序博客网 时间:2024/05/25 23:59
/*并查集*/#include <iostream>using namespace std;const int MAXN = 50005;int father[MAXN];int n, m, cas = 0, sum;void init(){for (int i = 0; i < n; ++i) {father[i] = i;}return;}int getfather(int x){if (x != father[x])father[x] = getfather(father[x]);return father[x];}void merge(int x, int y){int fx = getfather(x);int fy = getfather(y);if (fx != fy) {father[fy] = fx;--sum;}}int main(){while (cin >> n >> m && (n + m)) {init();sum = n;int x, y;for (int i = 0; i < m; ++i) {cin >> x >> y;merge(x, y);}cout << "Case " << ++cas << ": " << sum << endl;}return 0;}
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
- 开通个人博客,欢迎交流
- js闭包
- UITextField的使用详解
- PhoneGap/Cordova Android应用签名发布注意事项
- BOE.war redeployed, java.lang.RuntimeException: Could not find framework 解决办法
- POJ2524 Ubiquitous Religions
- Linux traceroute
- 2014年7月15日中午笔记
- VC++学习心得(九)
- 使用java画出宝马图标代码
- Zend Studio 10 代码格式化配置
- ubuntu引导修改
- leetcode copy list with random pointer
- Unity3D之利用C#实现代理模式