【并查集】:poj2524,Ubiquitous Religions
来源:互联网 发布:mac微信语音导出软件 编辑:程序博客网 时间:2024/05/01 08:56
http://poj.org/problem?id=2524
题目描述:
世界上宗教何其多。假设你对自己学校的学生总共有多少种宗教信仰很感兴趣。学校有n个学生,但是你不能直接问学生的信仰,不然他会感到很不舒服的。有另外一个方法是问m对同学,是否信仰同一宗教。根据这些数据,相信聪明的你是能够计算学校最多有多少种宗教信仰的。
# include<iostream># include<string.h># include<map>using namespace std;# define N 50005int data[N];void MakeSet(int n){for(int i=1;i<=n;i++){data[i]=i;}}int Find(int i){if(i==data[i]){return i;}else{//return Find(data[i]);data[i]=Find(data[i]);return data[i];}}void Union(int i, int j){int ip=Find(i);int jp=Find(j);if(ip!=jp){data[ip]=jp;}}int main(){int i,j,k,n,m,t;map<int, int> mp;t=0;while(true){cin>>n>>m;if(n==0 && m==0){break;}mp.clear();MakeSet(n);for(i=1;i<=m;i++){cin>>j>>k;Union(j,k);}for(i=1;i<=n;i++){//mp[data[i]]=1;mp[Find(i)]=1; //注意}cout<<"Case "<<++t<<": "<<mp.size()<<endl;}return 0;}
0 0
- 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(并查集)
- POJ2524——Ubiquitous Religions 并查集基础
- POJ2524 Ubiquitous Religions —— 并查集
- 工作常用Linux命令
- 手动创建servlet
- Java基础---图形用户界面GUI(二)
- WIN32 API 打开大于10序号的串口注意写法
- 如何实现百度mapv开源库与ol3的结合
- 【并查集】:poj2524,Ubiquitous Religions
- C# 任意形状按钮控件 实现简单实用
- android 获取WebView的网页高度
- 杭电HDU1087
- java.lang.NoClassDefFoundError的几种原因与解决方法
- 异常总结,持续更新
- ContextLoaderListener(1)---WebApplicationContext创建过程
- 实习整理(十六)
- spinner的使用