poj 2524 Ubiquitous Religions(无所不在的宗教)
来源:互联网 发布:小马激活软件 编辑:程序博客网 时间:2024/04/29 04:06
这是一道并查集的水题,套用模板就行了。
#include<stdio.h>int arr[50005];int find(int x){int k, j, r; r = x; while(r != arr[r]) r = arr[r]; k = x; while(k != r) { j = arr[k]; arr[k] = r; k = j; } return r; }void merge(int a, int b){int fx=find(a);int fy=find(b);if(fx!=fy)arr[fx]=fy;}int main(){int n,m,count,k=0;int a,b;while(~scanf("%d%d",&n,&m),n,m){for(int i=1;i<=n;i++)arr[i]=i;for(int i=0;i<m;i++){scanf("%d%d",&a,&b);merge(a,b);}count=0;for(int i=1;i<=n;i++){if(arr[i]==i)count++;}k++;printf("Case %d: %d\n",k,count);}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
- CSS 和JavaScript 在ie6 ie7 ie8和Firefox下bug兼容解决记录
- Palindrome Transformation - CodeForces 486 C 水题
- Xen 安装图解教程
- Hard limits for "maximum open file descriptors"
- Java---Socket编程基础理论
- poj 2524 Ubiquitous Religions(无所不在的宗教)
- Sublime Text3中字体设置
- LeetCode——Valid Number
- Eclipse 改变背景色
- 短信模块(一)
- java项目中引入Junit测试库
- 问题集一:view.setLayoutParams(layoutParams)不起作用
- n个骰子各点数和出现的概率--动态规划
- android Wifi热点