POJ 2524 :Ubiquitous Religions
Time Limit: 5000MS | Memory Limit: 65536K | |
Total Submissions: 23171 | Accepted: 11406 |
Description
in.
You know that there are n students in your university (0 < n <= 50000). It is infeasible for you to ask every student their religious beliefs. Furthermore, many students are not comfortable expressing their beliefs. One way to avoid these problems is to ask
m (0 <= m <= n(n-1)/2) pairs of students and ask them whether they believe in the same religion (e.g. they may know if they both attend the same church). From this data, you may not know what each person believes in, but you can get an idea of the upper bound
of how many different religions can be possibly represented on campus. You may assume that each student subscribes to at most one religion.
Input
in the same religion. The students are numbered 1 to n. The end of input is specified by a line in which n = m = 0.
Output
Sample Input
10 9
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
10 4
2 3
4 5
4 8
5 8
0 0
Sample Output
Case 1: 1
Case 2: 7
额。。难道题单错了?。。
。我一看就是并查集。
。所以就这么水过了。。
并查集一A水过
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<sstream>
#include<cmath> using namespace std; #define M 100500
int p[M];
int n, m; void start()
{
for(int i=1; i<=n; i++)
p[i] = i;
} int find(int x)
{
return p[x] == x ? x : p[x] = find( p[x] );
} void Kruskal(int x, int y)
{
int xx = find(x);
int yy = find(y);
if(xx!=yy)
p[yy] = xx;
} int main()
{
int cas = 0;
while(scanf("%d%d", &n, &m) &&n &&m)
{
cas++;
start();
int ans = 0;
for(int i=1; i<=m; i++)
{
int x; int y;
scanf("%d%d", &x, &y);
Kruskal(x, y);
}
for(int i=1; i<=n; i++)
{
if( p[i]==i )
ans++;
}
printf("Case %d: %d\n", cas, ans);
} return 0;
}
POJ 2524 :Ubiquitous Religions的更多相关文章
- 【48.47%】【POJ 2524】Ubiquitous Religions
Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 32364 Accepted: 15685 Description There a ...
- POJ2524:Ubiquitous Religions (并查集模板)
Description There are so many different religions in the world today that it is difficult to keep tr ...
- 【原创】poj ----- 2524 Ubiquitous Religions 解题报告
题目地址: http://poj.org/problem?id=2524 题目内容: Ubiquitous Religions Time Limit: 5000MS Memory Limit: 6 ...
- poj 2524:Ubiquitous Religions(并查集,入门题)
Ubiquitous Religions Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 23997 Accepted: ...
- POJ 2524 Ubiquitous Religions
Ubiquitous Religions Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 20668 Accepted: ...
- Ubiquitous Religions 分类: POJ 2015-06-16 17:13 11人阅读 评论(0) 收藏
Ubiquitous Religions Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 26678 Accepted: ...
- poj 2524 Ubiquitous Religions(宗教信仰)
Ubiquitous Religions Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 30666 Accepted: ...
- [ACM] POJ 2524 Ubiquitous Religions (并查集)
Ubiquitous Religions Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 23093 Accepted: ...
- poj 2524 Ubiquitous Religions 一简单并查集
Ubiquitous Religions Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 22389 Accepted ...
随机推荐
- 1.1.2-学习Opencv与MFC混合编程之---画图工具 画直线 画圆 画矩形
源代码地址:http://download.csdn.net/detail/nuptboyzhb/3961685 画图工具 1. 画直线 Ø 增加‘直线’菜单项,建立类向导: Ø 对CXX ...
- ORA-00942:表或视图不存在(低级错误)
在好多时候.调试PL/SQL对象时会报.ORA-00942 看看错误原因吧: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvamFjc29uX2JhaQ== ...
- C++ 观察者模式样例
C++ 观察者模式样例 #include <iostream> #include <set> #include <string> using namespace s ...
- 第三天学习内容 if--else
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...
- jQuery事件大全
jQuery事件大全 attribute: $(" p" ).addclass(css中定义的样式类型) 给某个元素添加样式 $(" img" ).attr( ...
- iphone缩小uIImage图片
UIImage的缩小 有时候,项目中,要用到上传图片,从图片库里取出的图片有的太大了,而要上传的时候,会很费时间,而且也没必要太大,所以就把图片综缩小一下,再传! #pragma UIImagePic ...
- linux下的php网站放到Windows服务器IIS下.htaccess文件伪静态规则转换
此办法只适合于linux下的php网站放到Windows服务器IIS下 , 网站除了主页面正常以外 子页面全部出现404错误 这里子页面出现404 错误是说明伪静态没有开启 什么是.htac ...
- CImage类
CImage封装了DIB(设备无关位图)的功能,因而可以让我们能够处理每个位图像素.这里介绍GDI+和CImage的一般使用方法和技巧. TAG: GDI CImage 后处理 我们知道,Vi ...
- Sql Server中COUNT(字段名)跟COUNT(*)的特殊不同点
今天有个需求,有2张表: 1.一个“搜索记录”表search,一个“搜索后下载记录”表down 2.映射关系:每一个下载记录对应一条搜索记录, 第个 ...
- C#数学运算表达式解释器
C#数学运算表达式解释器 測试文件内容: a=2+3*2; b=2*(2+3); 浏览按钮事件处理程序: private void button_browse_Click(object sender, ...