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 ...
随机推荐
- 美化 - DropDownList控件
地址:http://www.baidufe.com/component/dropdownlist/index.html 效果: 引用JS文件: <link href="Js/DropD ...
- Qt Style Sheets Examples(QT真是有很全的文档)
http://doc.qt.io/qt-5/stylesheet-examples.html http://doc.qt.io/qt-4.8/stylesheet.html
- c# in depth之泛型的实现
1.默认值表达式 如果已经明确了要处理的类型,也就知道了它的“默认”值.不知道要引用的类型,就不能直接指定默认值.不能使用null,因为它可能不是一个引用类型,不能使用0,因为它可能不是数值类型.虽然 ...
- JavaScript快速入门(二)——JavaScript变量
变量声明 JavaScript的变量声明分为显式声明跟隐式声明. 显式声明 即带var关键字声明,例如 var example = example; 要注意JavaScript里面声明的关键字只有fu ...
- MongoDB学习笔记(四) 用MongoDB的文档结构描述数据关系
MongoDB的集合(collection)可以看做关系型数据库的表,文档对象(document)可以看做关系型数据库的一条记录.但两者并不完全对等.表的结构是固定的,MongoDB集合并没有这个约束 ...
- Qt之生成Window资源文件(.rc 文件)
简述 qmake 可以随意地自动生成一个适当填充的 Windows 资源文件.本节主要讲解如何用 qmake 处理一个 Windows 资源文件,并将其链接到一个可执行应用程序(EXE)或动态链接库( ...
- 让AllocateHwnd接受一般函数地址作参数(105篇博客)
http://www.xuebuyuan.com/1889769.html Classes单元的AllocateHWnd函数是需要传入一个处理消息的类的方法的作为参数的,原型: function Al ...
- mongodb查询分页优化
要求不用skip 前提:1.时间倒序排列(自己现在的项目中也是按照时间倒序排列的) 2.每页显示10条数据 int limit = 10;//刚开始点击查询的时候设置十条 查询形式为 db ...
- Maven 建 Struts2 基本实现 CURD Controller
开发环境 开发工具:Eclipse 数据库:MySQL server:Tomcat Struts2 请求原理流程图 构建一个 web maven project,在pom.xml引入struts2的j ...
- virus.win32.parite.H病毒的查杀方法
virus.win32.parite.H病毒的查杀方法 昨天电脑中了virus.win32.parite.H病毒,搞了2个多小时最终搞定了.以下记录下我的解决方法. 第一步:下载Win32.Parit ...