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 ...
随机推荐
- SRM 583 Div II Level Three:GameOnABoard,Dijkstra最短路径算法
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12556 用Dijkstra实现,之前用Floyd算法写了一个, ...
- [置顶] android关机闹钟设计思路
1: 首先需要硬件支持,支持alarm中断触发开机,目前高通平台几乎都支持: 2:关机前需要在rtc-xxx.c中做到enable_irq_wake,和不disable alarm功能(默认开机后al ...
- DELPHI 通過窗口句柄或窗口标题得到进程句柄
DELPHI 通過窗口句柄或窗口标题得到进程句柄2009年05月08日 星期五 10:15procedure TForm1.Button1Click(Sender: TObject);varhWind ...
- 用 managedQuery() 时须要注意的一个陷阱
Activity 里面提供了一个 managedQuery() 方法,依照 Android SDK 里面的说明,"the activity will manage its lifecycle ...
- PowerShell与Unix Shell对比:八大实例
PowerShell与Unix Shell对比:八大实例 本文将从八个实例对比PowerShell和Unix Shell,通常是Linux Bourne Shell(包括sh.ksh和bash等).二 ...
- Delphi回调函数及其使用
Delphi回调函数及其使用 1 回调函数的概述 回调函数是这样一种机制:调用者在初始化一个对象(这里的对象是泛指,包括OOP中的对象.全局函数等)时,将一些参数传递给对象,同时将一个调用者可以访问的 ...
- C++易vector
很长一段时间没有动手编写C++计划.无非就是模仿后STL对,虽然达不到标准STL该程序.但简单的功能来实现. STL事实上,深刻:泛型编程.容器.算法.适配器...有的是内容能够学.以下是依据STL源 ...
- [Android学习笔记]ScrollView的使用
竖直滚动使用ScrollView 水平滚动使用HorizontalScrollView 如果需要禁止ScrollView的滚动,则需要扩展ScrollView类,重写onTouchEvent方法.
- 14.4.1 InnoDB Startup Configuration
14.4 InnoDB Configuration :InnoDB 配置: 14.4 InnoDB Configuration 14.4.1 InnoDB Startup Configuration ...
- Java基础之数组序列化、反序列化 小发现(不知道 是不是有问题)
结论: 数组,无论是否声明为transient,都是可以序列化.反序列化的. 测试情况如下: 1.两种类型的数组:int .String: 2 声明为transient 或者不做任何修饰:. 3. ...