HDU 1213 How Many Tables

【RK3588开发记录】超详细的RK3588修改debug串口波特率为115200 修改RK3588的debug串口为115200 阅读详情

How Many Tables

https://vjudge.net/problem/HDU-1213
Today is Ignatius’ birthday. He invites a lot of friends. Now it’s dinner time. Ignatius wants to know how many tables he needs at least. You have to notice that not all the friends know each other, and all the friends do not want to stay with strangers.

One important rule for this problem is that if I tell you A knows B, and B knows C, that means A, B, C know each other, so they can stay in one table.

For example: If I tell you A knows B, B knows C, and D knows E, so A, B, C can stay in one table, and D, E have to stay in the other one. So Ignatius needs 2 tables at least.
Input
The input starts with an integer T(1<=T<=25) which indicate the number of test cases. Then T test cases follow. Each test case starts with two integers N and M(1<=N,M<=1000). N indicates the number of friends, the friends are marked from 1 to N. Then M lines follow. Each line consists of two integers A and B(A!=B), that means friend A and friend B know each other. There will be a blank line between two cases.
Output
For each test case, just output how many tables Ignatius needs at least. Do NOT print any blanks.
Sample Input
2
5 3
1 2
2 3
4 5

5 1
2 5
Sample Output
2
4
C++

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int MAXN = 1000 + 10;
int fa[MAXN];
int n, m;

void init()
{
	for(int i = 1; i <= n; i ++)
		fa[i] = i;
}

int find(int x)
{
	if(fa[x] == x) return x;
	return fa[x] = find(fa[x]);
}

void merge(int x, int y)
{
	int tx = find(x);
	int ty = find(y);
	if(tx != ty)
		fa[tx] = ty;
}

int main()
{
	int T;
	scanf("%d", &T);
	while(T --)
	{
		scanf("%d%d", &n, &m);
		init();
		int a, b;
		for(int i = 0; i < m; i ++)
		{
			scanf("%d%d", &a, &b);
			merge(a, b);
		}
		int ans = 0;
		for(int i = 1; i <= n; i ++)
			if(fa[i] == i) ans ++;
		printf("%d\n", ans);
	}
	return 0;
}
Yakit实战:利用验证码识别插件突破Webfuzzer自动化测试瓶颈 本文详细介绍了如何利用Yakit的Webfuzzer模块结合验证码识别插件,突破自动化安全测试中的验证码瓶颈。通过实战演示,讲解了如何部署本地OCR服务、编写热加载脚本,实现从获取验证码到自动识别并替换的全流程自动化,从而让Webfuzzer能够高效、无人值守地进行大规模密码喷洒等测试。 阅读详情

相关推荐

W25N01GV SPI NAND Flash驱动开发避坑指南:详解2KB缓冲区机制与状态寄存器正确用法

本文深入解析W25N01GV SPI NAND Flash芯片的2KB缓冲区机制与状态寄存器正确用法,提供STM32 HAL和ESP-IDF项目的实战解决方案。涵盖双阶段操作原理、状态寄存器深度解析、时序控制优化及跨平台驱动设计要点,帮助开发者避免常见错误并提升存储性能。

aizhouqian5537的博客 640

hdu 1213 How Many Tables

How Many Tableshttp://acm.hdu.edu.cn/showproblem.php?pid=1213 Problem DescriptionToday is Ignatius' birthday. He invites a lot of friends. Now it's dinner time. Ignatius wants to know how many t...

weixin_30384031的博客 105

从零构建NVENC编码器:一个游戏开发者的实战手册

本文详细介绍了如何从零构建NVENC编码器,特别针对游戏开发者提供实战指南。内容涵盖NVENC基础概念、DirectX纹理捕获、异步编码优化及高级特性配置,帮助开发者高效集成硬件编码技术到游戏引擎中,实现高性能游戏录制和直播功能。重点解析了NVIDIA专用编码芯片的优势与API使用技巧。

weixin_29292431的博客 365

并查集 How many tables(hdu 1213) How many answers are wrong(hdu 3038)

感觉并查集总共有两个应用,一是解决有关群的问题,二是利用并查集构造一个只有叶子的高效权值树。比方说a和b是朋友b和c是朋友,那么a,b,c这三个人在并查集中就属于同一个集合,如果经过路径压缩后a,b,c三个人的集合就会指向一处。

2301_80093604的博客 1446

ADRV9009学习资料保存:基于XC7Z100+ADRV9009的双收双发无线电射频板卡

ADRV9009学习资料保存:基于XC7Z100+ADRV9009的双收双发无线电射频板卡 一、板卡概述 基于XC7Z100+ADRV9009的双收双发无线电射频板卡是基于XilinxZYNQFPGA和ADI的无线收发芯片ADRV9009开发的专用功能板卡,用于5G小基站,无线图传,数据收发...

9356

【嵌入式笔试题】C语言笔试题(4)

嵌入式C语言综合笔试题

m0_74055118的博客 1066

HDU 1213 How Many Tables

HDU 1213 How Many Tables 简单并查集 #include&lt;stdio.h&gt; #include&lt;iostream&gt; #include&lt;algorithm&gt; #include&lt;stdlib.h&gt; #include&lt;string.h&gt; using namespace std; const int maxn=100...

LMengi000的博客 300

ClickHouse分布式表原理:大数据分片存储与查询

我是一名资深大数据工程师,专注于ClickHouse优化和分布式架构设计。拥有5年以上大数据开发经验,曾为多家电商、金融公司提供ClickHouse解决方案。欢迎关注我的博客(),一起探讨大数据技术!留言互动:你在使用ClickHouse分布式表时遇到过什么问题?欢迎在评论区分享,我会一一解答!

AI大模型应用之禅 959

[HDU 1213]How Many Tables

[HDU 1213]How Many Tables 题目链接: 注意:从1开始循环,一定要循环到n啊(&lt;=n) 1 #include&lt;iostream&gt; 2 #include&lt;cstdio&gt; 3 using namespace std; 4 5 const int maxn = 1010; ...

Youpeng 113

向华为学习——IPD流程体系之IPD术语

《IPD体系核心概念与业务术语解析》摘要: IPD(集成产品开发)是一种以市场为导向的结构化产品开发管理模式,通过跨部门协作、异步开发、CBB(通用构建模块)和管道管理等手段,实现产品全生命周期高效管理。体系包含七大核心要素:跨部门团队(如IPMT决策层、PDT执行层)、结构化流程(分阶段评审)、端到端项目管理(WBS分级计划)、客户需求分析、投资组合优化及质量管控(TR技术评审)。各业务领域术语涵盖财务(NPV、IRR)、开发(需求分解、基线化)、制造(可制造性设计)、采购(Sourcing团队)及市场(

cdfunlove的博客 481

OKX 欧易 交易机器人开发基础

接口文档: https://www.okx.com/docs-v5/zh/#overview REST API 常用请求 查看账户余额 结果数据格式: 获取限价 结果格式: 获取指数行情 数据结构: 下单 结果数据: 获取未成交订单列表 返回结果: 撤单 结果结构:

Willin Wang 的全栈升级指南 2万+

HDU 1213How Many Tables

How Many Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 14169    Accepted Submission(s): 6949 Problem Description Today is

wust_ZJX的专栏 879

斑鬣狗优化算法(SHO)详解:从生物原理到代码实战

斑鬣狗优化算法(SHO)是一种新型元启发式优化算法,灵感来源于斑鬣狗的群体狩猎行为。该算法通过模拟斑鬣狗的包围猎物、协同狩猎和攻击猎物等生物行为,将优化问题转化为智能搜索过程。SHO算法包含探索与开发两个阶段,通过数学模型实现群体协作和自适应平衡,具有参数简单、收敛快等优势。文章系统介绍了SHO的生物基础、数学模型、实现方法(包括MATLAB和Python代码)、改进策略以及在函数优化、路径规划等领域的应用案例,最后讨论了算法的优势、局限性和未来研究方向。

qq_42212808的博客 237

HDU-1213 How Many Tables

HDU-1213 How Many Tables 题目链接:HDU-1213 题目大意:分配坐席 认识的可以分配在一个桌子,如果a认识b,b认识c则abc就可以在一个桌子,问一共需要准备多少桌子 解题思路:并查集模版题 代码块: #include<iostream> #include<cstring> using namespace std; int arrA[100...

鱼头的水题之路 271

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

HDU1213 How Many Tables

How Many Tables                                                    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

yedengmei的博客 375

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

Hdu1213 How Many Tables

How Many Tables Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 52180Accepted Submission(s): 25883 Problem Description ...

那一夜见红的博客 229

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

How Many Tables——HDU 1213

并查集

weixin_44750790的博客 295

HDU 1213 How Many Tables(并查集)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1213 解题思路:并查集裸题。 并查集两大功能:①合并两个集合②查找某个元素在哪个集合 若并查集数组为uf[],则uf[i]表示编号为i的点的“上级”,如果uf[i] = i表示当前的点是一个集合的“大头目”。 int find1(int x)///找到大头目 { int r = x;...

shadiao.的博客 227

How Many Tables(hdu-1213)

点我跳转到 HDU - 1213 Problem Description Today is Ignatius’ birthday. He invites a lot of friends. Now it’s dinner time. Ignatius wants to know how many tables he needs at least. You have to notice that not all the friends know each other, and all the frien.

Silence的博客 223

HDU1213 How Many Tables

原题链接: http://acm.hdu.edu.cn/showproblem.php?pid=1213 1.并查集的简单实现: #include <bits/stdc++.h> using namespace std; const int maxn = 1050; int s[maxn]; /** * 初始化 */ void init_set() { for (int i = 1; i <= maxn; ++i) { s[i] = i; } } /

醉后不知天在水,满船清梦压星河 232

【并查集】HDU 1213 How Many Tables

HDU 1213 How Many Tables #include <iostream> #include <cstdio> #include <algorithm> #include <queue> #include <cmath> #include <cstring> #include <string> #in...

L_X_ 158

hdu 1213 How Many Tables(dfs)

hdu 1213 How Many Tables Problem DescriptionToday is Ignatius' birthday. He invites a lot of friends. Now it's dinner time. Ignatius wants to know how many tables he needs at least. You have...

diansitao5461的博客 151
上一篇: POJ 1611 The Suspects
下一篇: HDU 1166 敌兵布阵
剑气扬名
博客等级 码龄7年 24粉丝 79原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值