POJ 2524 Ubiquitous Religions(并查集)

别再手动配电脑了!手把手教你用Windows Server 2022搭建企业AD域(附DNS配置避坑指南) 本文详细介绍了如何使用Windows Server 2022搭建企业AD域,提升20+终端的管理效率。通过实战案例和避坑指南,解析AD域的核心价值、部署步骤及DNS配置技巧,帮助企业实现集中权限管理、安全策略统一部署,显著降低IT运维成本。 阅读详情

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. 

题意描述:

给出n个学生,学生编号为1-n,然后给出m组学生的编号,每组有两个学生,表示这两个学生信仰同一个宗教。问这n个学生中信仰了多少个不同的宗教。

AC代码:

#include<stdio.h>**

int f[50005];

void inti(int n)
{
	for(int i=1;i<=n;i++)
		f[i]=i;
	return ;
}

int fget(int i)
{
	if(f[i]==i)
		return i;
	f[i]=fget(f[i]);
	return f[i];
}

void merge(int x,int y)
{
	int t1,t2;
	t1=fget(x);
	t2=fget(y);
	
	if(t1!=t2)
		f[t2]=t1;
	return ; 
}

int main(void)
{
	int n,m,i,x,y,t=1;
	while(~scanf("%d%d",&n,&m)){
		if(m==0&&n==0)
			break;
		
		inti(n);
		for(i=1;i<=m;i++){
			scanf("%d%d",&x,&y);
			merge(x,y);
		}
		
		int count=0;
		for(i=1;i<=n;i++)
			if(f[i]==i)
				count++;
		printf("Case %d: %d\n",t++,count);
	}
	return 0;
}
如何使用 Conda 安装 Qiskit(详细教程) 本文介绍了使用conda安装Qiskit量子计算工具包的完整流程。首先创建Python 3.10的conda虚拟环境(qiskit_env),然后安装Qiskit核心包及可视化组件(注意Mac用户的安装命令差异)。接着注册IPython内核并测试环境,通过量子电路创建与可视化演示验证安装成功。该教程为量子计算开发提供了简洁的环境配置指南,适合研究者和开发者快速搭建Qiskit开发环境。 阅读详情

相关推荐

RAGFlow系列(06):从0.20.0版本升级到最新版的完整指南

本文提供了从RAGFlow 0.20.0版本升级到最新版的完整指南。升级前务必进行数据、配置和状态的三层备份,尤其是智能体配置因版本间存在不兼容风险。指南详细说明了如何优雅停止服务、拉取新代码、检查并调整配置文件(如端口、环境变量),以及最终部署验证的步骤,确保升级过程平滑安全。

weixin_29243279的博客 464

POJ-2524Ubiquitous Religions(并查集)

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 beli...

weixin_44313771的博客 297

用Python和CasADi实现高斯伪谱法:一个轨迹优化问题的保姆级教程

本文详细介绍了如何使用Python和CasADi框架实现高斯伪谱法解决轨迹优化问题。通过保姆级教程,从环境准备、问题建模到高斯伪谱法的核心实现,包括配点与权重计算、微分矩阵构造和动力学约束实现,最终完成问题求解与结果可视化。适用于机器人轨迹规划和无人机路径优化等工程场景。

weixin_30776273的博客 294

POJ 2524 Ubiquitous Religions

<br />Ubiquitous ReligionsTime Limit: 5000MS Memory Limit: 65536KTotal Submissions: 12668 Accepted: 6018<br />DescriptionThere are so many different religions in the world today that it is difficult to keep track of them all. You are interested in finding

hqd_acm的专栏 761

【ESP32】SPI SRAM memory test fail。External RAM failed memory test!

log日志报错如下:这两条报错信息表明外部 SPI SRAM(静态随机存取存储器)的内存测试失败。

weixin_56217406的博客 1024

Eplan P8 API二次开发--插入符号(Symbol)功能(Function)并定义属性

1、目的 使用Eplan API在页中自动插入某个符号并按约定规则自动设置好属性 2. 步骤 一、基础信息 比如要在Eplan中自动插入一个电机的符号并定制属性,我们先要确定要插入的符号名,可以在Eplan中获取如下符号(Symbol)信息 可以知道我们待插入的符号名称为M3_1, 接下来,使用Visual Studio建立类库项目,并引用Eplan Api库 二、获取符号变量(SymbolVariant) 在Eplan中,当一个符号(Symbol)被插入到页中,这个符号的引用即变为一个(Function

如是道程序人生 4529

POJ-2524 Ubiquitous Religions (并查集)

POJ-2524 Ubiquitous Religions (并查集) 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 diff...

碳酸钙的01妖精的博客 250

从零开始讲DDR(8)——AXI 接口MIG 使用(1)

我们简单拆解了MIG AXI接口中测试文件的整体框架,首先在sim_tb_top.sv文件中例化了DDR模型和example_top。在example_top中,又例化了MIG IP和一个流量产生器ddr4_v2_2_8_axi_tg_top。在ddr4_v2_2_8_axi_tg_top中的主要功能是分别例化了boot_mode_gen,prbs_mode_gen,custom_mode_gen和axi_opcode_gen。

apple_53311083的博客 1593

POJ 2524 Ubiquitous Religions(并查集)

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 beli...

weixin_44606952的博客 218

TSP:车为什么能和云端交互?

TSP:车为什么能和云端交互?

天赐好车的博客 414

python:实现矩阵SVD分解(附完整源码)

python:实现矩阵SVD分解(附完整源码)

希望我的博客,能帮上你解决学习中工作中所遇到的问题 603

并查集 初探

Ubiquitous Religions 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...

BenFromHRBUST的优快云博客 302

【FF-A】第四章 Concepts

SPM的责任分为两个组件:SPM调度器(SPMD)和SPM核心(SPMC)。这两个组件都可以访问整个物理地址空间,并且是受信任的计算基础的一部分。当无需区分这两个组件时,术语SPM被使用。这些组件的责任如下所示。SPMD 位于 EL3 中,以 AArch64 或 AArch32 执行状态运行。SPMC 可以与 SPMD 共存在 EL3 中,也可以位于相邻的异常级别,即 S-EL1 或 S-EL2。SPM 在启动时初始化 EL3 LSP,并在运行时促进它们与其他端点之间的通信。

baron-周贺贺-代码改变世界ctw 1195

【并查集】POJ 2524 Ubiquitous Religions

POJ 2524 Ubiquitous Religions #include <iostream> #include <cstdio> #include <algorithm> #include <queue> #include <cmath> #include <cstring> #include <string&gt...

L_X_ 207

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

POJ 2524 Ubiquitous Religions 并查集

题意:现在在弄一个大学调查,调查的内容就是,大学生群体的信仰。 如果测试样例输入 1 2 就代表 1 2 拥有同样的信仰。 最后问你最多有多少个不同的 信仰。显然这是一个并查集的题目。而且是模版题目。传送门:POJ-2524-Ubiquitous Religions#include <stdio.h> int pre[50005]; int Find(int x) { int r=x;

知 识 不 是 装 饰。 348

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

poj 2524 Ubiquitous Religions(并查集)

题目链接:poj 2524 Ubiquitous Religions 题目大意:

不慌不忙、不急不躁 846

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

POJ 2524-Ubiquitous Religions 并查集

题目来源:http://acm.pku.edu.cn/JudgeOnline/problem?id=2524解题报告:简单的并查集的应用吧#include using namespace std; typedef struct _node { _node* parent; int rank; }node; node **s; void makeSet(int x) { s[x]=new node; s[x]->rank=0; s[x]->parent=s[x]

kindlucy的专栏 786

Ubiquitous Religions POJ - 2524 并查集

Ubiquitous Religions POJ - 2524 并查集 #include<iostream> #include<algorithm> #define fori for(i=0;i<n;i++) #define fori1 for(i=1;i<=n;i++) #define ll long long const ll mod = 1e9 + 7; ...

ch_huibw的博客 189

POJ2524 Ubiquitous Religions —— 并查集

题目链接:http://poj.org/problem?id=2524 题解: 找出最多能有多少个不同的宗教,直接并查集就可以了。 第一次提交时没有注意到要输出“Case %d :”, 以后要注意了,细心读题。 代码如下: #include//B - Ubiquitous Religions POJ - 2524 纯并查集 #include #include #inc

A man can be destroyed, but not defeated. 454

POJ 2524 Ubiquitous Religions 并查集

题目描述 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 univers

u013087645的专栏 796

POJ 2524 Ubiquitous Religions【并查集】

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 i

memcpy0的博客 539

poj 2524 Ubiquitous Religions(并查集)

题目链接:http://poj.org/problem?id=2524 Ubiquitous Religions Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 33619   Accepted: 16258 Description

far away 295

POJ 2524题解   Ubiquitous Religions(并查集)

这道题是并查集简单题,题目如下: 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 the

Jayus_Jocker的博客 425

poj 2524 Ubiquitous Religions [并查集]

Ubiquitous Religions Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 31544   Accepted: 15284 Description There are so many different religions in the world t

Ariesc_jch 317

POJ 2524 Ubiquitous Religions 详细题解(并查集)

题目链接:http://poj.org/problem?id=2524   这道题属于并查集     题目大意: 在一个学校内调查学生的信仰情况,告诉你学校有n个人,给你共m组x,y表示信教情况相同,问一个学校学生信仰的宗教的最大种数   这也是一道模板题,没啥说的,我在另一篇文章里面讲过模板题的做法,大家可以参考下。http://blog.youkuaiyun.com/xdz78/artic

Mastli's Blog 699

POJ2524 Ubiquitous Religions 并查集

1.题目描述: 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 un

终有绿洲摇曳在沙漠 283
上一篇: POJ 3050 Hopscotch(dfs暴力)
下一篇: 操作系统的一道题
鳳九~
博客等级 码龄8年 1384粉丝 215原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值