More is better

『杭电1856』More is better Problem Description Mr Wang wants some boys to help him with a project. Because the project is rather complex,the more boys come, the better it will be. Of course there are certain requirements. Mr Wang selected a room big enough to hold the boys. The b. 阅读详情

点击打开链接

Mr Wang wants some boys to help him with a project. Because the project is rather complex,  the more boys come, the better it will be. Of course there are certain requirements. 

Mr Wang selected a room big enough to hold the boys. The boy who are not been chosen has to leave the room immediately. There are 10000000 boys in the room numbered from 1 to 10000000 at the very beginning. After Mr Wang's selection any two of them who are still in this room should be friends (direct or indirect), or there is only one boy left. Given all the direct friend-pairs, you should decide the best way. 
Input
The first line of the input contains an integer n (0 ≤ n ≤ 100 000) - the number of direct friend-pairs. The following n lines each contains a pair of numbers A and B separated by a single space that suggests A and B are direct friends. (A ≠ B, 1 ≤ A, B ≤ 10000000)
Output
The output in one line contains exactly one integer equals to the maximum number of boys Mr Wang may keep. 
Sample Input
4
1 2
3 4
5 6
1 6
4
1 2
3 4
5 6
7 8
Sample Output
4
2


#include<stdio.h>
const int M = 10000000 + 10;
int num,vis[M],par[M];
int find(int x)
{
	return x==par[x]?x:par[x]=find(par[x]);
}
void unite(int x,int y)
{
	int fx=find(x),fy=find(y);
	if(fx!=fy){
		vis[fx]+=vis[fy];
		par[fy]=fx;
	}
}
int main()
{
	int n,m;
	while(~scanf("%d",&n)){
		m=n;
		for(int i=0;i<M;i++) {
			par[i]=i;
			vis[i]=1;
		}
		num=1;
		int x,y;
		while(m--){
			scanf("%d%d",&x,&y);
			unite(x,y);
		}
		
		printf("%d\n",num);
	}
}


NVIDIA Orin AGX开发环境搭建避坑指南:从Ubuntu 22.04到ROS2完整配置流程 本文详细介绍了NVIDIA Orin AGX开发环境搭建的全流程,从Ubuntu 22.04系统安装到ROS2深度优化,涵盖驱动部署、CUDA环境配置、散热与功耗管理等关键步骤。特别针对Orin AGX的特性提供了实用避坑指南和性能优化技巧,帮助开发者高效完成开发环境配置。 阅读详情

相关推荐

平衡小车动力学建模

两轮自平衡小车由车体和双轮两部分组成,可以看成一个移动的倒立摆,分别对车轮和车体进行力学分析,建立动力学模型,最后,通过对两者的分析给出系统的状态空间表达式。[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-kjiPEUVJ-1679470559950)(C:\Users\DELL\AppData\Roaming\Typora\typora-user-images\image-20230322110521545.png)]

qq_23096319的博客 9056

hdu 1856 More is better 并查集(二)

More is better Problem Description Mr Wang wants some boys to help him with a project. Because the project is rather complex, the more boys come, the better it will be. Of course there are cer

土>南瓜地 682

通过TMS320F28335学习DSP的开发流程——28335的基础知识(1)

1、TMS320F28335内核的主要特点 ①F28335 DSP集成了DSP和微控制器的长处,如DSP的主要特征、单周期乘法运算,F28335能够在一个周期内完成32x32位的乘法累加运算,或者两个16x16位乘法累加运算,而同样32位的普通单片机则需要4个周期以上才能完成 ②快速的中断响应 ③可在任何内存位置进行单周期读、修改、写操作 ④可采用C/C++编程软件,效率非常高 2、处理器的主要资源 ①32位浮点DSP,主频是150MHz,方便电机控制、电力设备控制及工业控制等。 ②片上存储器:FLASH–

Kayboy的博客 2万+

More is better(并差集)

More is better Problem Description Mr Wang wants some boys to help him with a project. Because the project is rather complex, the more boys come, the better it will be. Of course there are certain req...

娄零的博客 1466

从 SAP ABAP 到 S/4HANA,SAML 2.0 单点登录到底是怎么跑起来的

在很多 SAP 项目里,SSO 不是一个锦上添花的功能,而是系统能不能顺利上线的基本门槛。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 1051

【4. BSP开发指南 - [4.6. 安全启动使用说明]】

【4. BSP开发指南 - [4.6. 安全启动使用说明]】

Sugar_wolf的博客 276

算法笔记练习 9.6 并查集 问题 D: More is better - 超级详细的思路讲解

算法笔记练习 题解合集 本题链接 题目 题目描述 Mr Wang wants some boys to help him with a project. Because the project is rather complex, the more boys come, the better it will be. Of course there are certain requirements....

Gorgeoustray 502

OpenOCD入门到精通:第 0 章 教程导读

摘要:本教程是OpenOCD嵌入式调试工具的完整指南,适合从新手到资深工程师的学习需求。内容涵盖基础配置、调试技巧、Flash编程、TCL脚本自动化、源码解析和二次开发,共8大部分30章。教程提供5种学习路线,可根据角色和目标灵活选择,配套资源包含示例代码和配置文件。通过系统学习,读者将掌握OpenOCD从使用到扩展的全套技能,成为嵌入式调试领域的专家。

从事嵌入式linux android驱动开发,拥有全栈能力 1941

Jobdu1444 More is better (并查集)

Jobdu1444 More is better 题目: Mr Wang wants some boys to help him with a project. Because the project is rather complex, the more boys come, the better it will be. Of course there are certain requirem

xx_ii 487

《AI编程实战:深度学习模型改进与系统部署》,改进专栏目录和介绍

专深度学习相关项目都写在本专栏,《一次订阅解锁全部,都有源码,永久观看》,包括车牌识别、股票预测、人脸识别、风格迁移、图像修复、图像超分辨重建、图像分割等任务,Web/PyQt系统实现。引入Transformer、Swin Transformer、DenseNet、ViT、ConvNeXt等算法实战,提供卷积改进,魔改对比实验,模型剪枝,模型蒸馏,模型量化,全网独家整合改进专栏,为不同领域的同学发表论文提供了大力支持。

在职AI算法工程师,擅长计算机视觉,YOLO目标检测、分割等,擅长web、pyqt界面可视化,好内容持续更新中,来这里跟大家一起学习,共同进步 3276

如何免费快速的部署一个自用免VIP的自动追剧工具!NAS新玩法!豆瓣与迅雷结合,轻松实现自动下载电影自动追剧功能(支持Windows,群晖nas,飞牛nas,软路由,服务器等Docker快速部署)

追剧党狂喜!豆瓣追剧神器,自动添加云盘,自动下载,微信通知,一键搞定!

XiaoqiangClub的博客 4590

hdu 1856 More is better(并查集)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1856 More is better Time Limit: 5000/1000 MS (Java/Others)Memory Limit: 327680/102400 K (Java/Others) Total Submission(s): 18985Accept...

weixin_30265171的博客 85

MATLAB基础应用精讲-【数模应用】信用评分模型(附R语言和python代码实现)

信用评分模型是近年来兴起的一种为了保障银行和其他金融部门的金融安全而设立的一种关于人身金融权限的划定模型。该模型指根据客户的信用历史资料,利用一定的信用评分模型,得到不同等级的信用分数,根据客户的信用分数,来决定客户所可以持有的金额权限,从而保证还款等业务的安全性。而随着在现代社会和公司中,贷款,信用卡的作用日渐突出,信用评分模型的发展前景不可估量。信贷风险是指借款人因偿还贷款或履行合同承诺而破产而产生损失的可能性。传统上,它与贷款人无法偿还所欠利息和本金、影响现金流和增加装配成本所产生的风险有关。

qq_36130719的博客 365

"less is better than more"?

"less > more",或者"less is better than more",是国外Unix界流传至今的一句玩笑话,指的是同用于文本交互式(分页)浏览的less命令和more命令,前者比后者要更好用。本文就来简要谈谈这两个命令。 more命令 more命令的第一版由Daniel Halbert在1978年写成,并首先引入到了BSD 3.0系统。该命令是Unix系统中第...

LittleMagic's Blog 1157

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

并查集——More is better

2130: More is better 题目描述 Mr Wang wants some boys to help him with a project. Because the project is rather complex, the more boys come, the better it will be. Of course there are certain re

qq_40510246的博客 277

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

hdu 1856 More is better(并查集)(卡空间,卡时间)(c++)

hdu 1856 More is better 题目链接: hdu 1856 More is better 题目大意: 输出最大数量的集合的数量 上代码: #include<iostream> #include<cstdio> #include<cstring> #include<cmath> using namespace std; typedef long long ll; #define N 10000005 int m; int x, y; int

谦卑 299

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

杭电1865 more is better

More is better Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 327680/102400 K (Java/Others) Total Submission(s): 18668    Accepted Submission(s): 6862 Problem Description Mr Wang want

hpuzsk的博客 653

C - More is better

哈哈哈哈。。。。。了解了知识点,做起来也得心应手了哈,,嘿嘿,不懂的童靴多看几遍就懂了,其实很简单嘛。。。 C - More is better Time Limit:1000MS     Memory Limit:102400KB     64bit IO Format:%I64d & %I64u Submit Status Description Mr W

u013246297的专栏 496

D - More is better

题目描述: Mr Wang wants some boys to help him with a project. Because the project is rather complex, the more boys come, the better it will be. Of course there are certain requirements. Mr Wang selected a...

年轻过成了秃顶 243
上一篇: 畅通工程
下一篇: WAJUEJI which home strong!
☞十一
博客等级 码龄9年 8粉丝 57原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值