POJ 2524 并查集

简介:
Ubiquitous Religions
Time Limit: 5000MS Memory Limit: 65536K
Total Submissions: 23580 Accepted: 11609
Description

There are so many different religions in the world today that it is difficult to keep track of them all. You are interested in finding out how many different religions students in your university believe 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

The input consists of a number of cases. Each case starts with a line specifying the integers n and m. The next m lines each consists of two integers i and j, specifying that students i and j believe 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

For each test case, print on a single line the case number (starting with 1) followed by the maximum number of different religions that the students in the university believe in.
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
Hint

Huge input, scanf is recommended.
Source

Alberta Collegiate Programming Contest 2003.10.18
 

</span>






本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/5247468.html,如需转载请自行联系原作者

相关文章
|
存储 缓存 安全
浅谈冯诺依曼体系和操作系统
浅谈冯诺依曼体系和操作系统
|
NoSQL 关系型数据库 MySQL
分布式锁的原理解析与实现工具介绍
分布式锁的原理解析与实现工具介绍
260 1
|
存储 编译器 Linux
C语言易错知识点总结2
C语言易错知识点总结2
104 0
|
设计模式 C#
C# 一分钟浅谈:工厂模式与抽象工厂模式
【10月更文挑战第10天】本文介绍了面向对象编程中的两种常见创建型设计模式:工厂模式和抽象工厂模式。工厂模式通过共同接口创建对象,隐藏创建逻辑,提高封装性和扩展性;抽象工厂模式则提供了一系列相关对象的创建接口,适用于多个相关产品族的创建。文章通过C#代码示例详细解释了这两种模式的实现和应用场景,并讨论了它们的优点、缺点及常见问题。
183 19
|
机器学习/深度学习 数据采集 算法
大数据与机器学习:数字时代的强大动力
在当今数字化时代,数据已经成为了一项宝贵的资源,而大数据和机器学习则是将其转化为实际价值的关键工具。本文将探讨大数据与机器学习的关系,以及它们如何共同推动技术、企业和社会的发展。
966 0
|
12月前
事务的隔离级别
在高并发情况下,并发事务会产生脏读、不可重复读、幻读问题,这时需要用隔离级别来控制 读未提交: 允许一个事务读取另一个事务已提交的数据,可能出现不可重复读,幻读。 读提交: 只允许事务读取另一个事务没有提交的数据可能出现不可重复读,幻读。 可重复读: 确保同一字段多次读取结果一致,可能出现幻读。 可串行化: 所有事务逐次执行,没有并发问题。
|
Java
Java面向对象编程,如何定义一个接口并在类中实现它?
Java面向对象编程,如何定义一个接口并在类中实现它?
302 1
|
存储
通讯录实现上
通讯录实现上
通讯录实现上
|
机器学习/深度学习 算法 计算机视觉
基于yolov2网络的人脸识别系统matlab仿真,包括识别正脸,侧脸等
基于yolov2网络的人脸识别系统matlab仿真,包括识别正脸,侧脸等
|
前端开发
巧用 CSS 构建渐变彩色二维码
巧用 CSS 构建渐变彩色二维码
538 0
巧用 CSS 构建渐变彩色二维码