HDU-1213 How Many Tables (并查集)

STM32CubeMX的正交编码器encoder 由于最近干活遇到需要获取正交编码的功能,所以返回来研究一下STM32CubeMX的编码器功能,之前也更新过STM32的定时器功能,但是因为之前搞平衡车的正交编码器没有搞清楚原理,就直接用了脉冲输入功能草草了事,现在也算是为之前的年轻买单了,不过看到现有的Encoder说明都比较简单,所以就当是为开发者做贡献了,我研究清楚之后来一篇博客。 阅读详情

                                   How Many Tables

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 52458    Accepted Submission(s): 26041

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

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

int pr[1005],n,m;
void init()
{
    for(int i=0;i<=n;i++)
        pr[i]=i;
}

int Find(int x)
{
    if(pr[x]!=x)
        pr[x]=Find(pr[x]);
    return pr[x];
}

void join(int x,int y)
{
    int a=Find(x),b=Find(y);
    if(a!=b)
        pr[b]=a;
    return ;
}


int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&n,&m);
        init();
        int a,b,cnt=0;
        for(int i=0;i<m;i++)
        {
            scanf("%d%d",&a,&b);
            join(a,b);
        }
        for(int i=1;i<=n;i++)
        {
            if(Find(i)==i)
                cnt++;
        }
        printf("%d\n",cnt);
    }
    return 0;
}

 

ChatUI vs Ant Design X 技术选型对比 维度ChatUI优势轻量级、易上手、完美兼容 Ant Design全能型框架、企业级扩展性、深度模型集成局限性功能单一、缺乏高级交互支持学习曲线陡峭、包体积较大最佳实践单独聊天窗口集成整体智能助手系统开发通过对比可见,ChatUI 适合快速实现基础对话功能,而Ant Design X 更适合构建复杂的 AI 驱动应用。实际选择时需结合项目规模、团队技术栈和对交互复杂度的需求综合评估。 阅读详情

相关推荐

用Arduino和MAX30102做个心率血氧仪,从硬件连线到算法调试全流程避坑

本文详细介绍了如何使用Arduino和MAX30102传感器构建高精度心率血氧仪,涵盖硬件连线、软件配置、信号处理及算法优化全流程。通过实战案例和避坑指南,帮助开发者快速实现临床级精度的健康监测设备,适用于可穿戴设备和医疗健康领域。

weixin_26897585的博客 383

并查集 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

知识图谱的数据挖掘与分析

1. 背景介绍 1.1 数据挖掘的崛起 随着互联网的普及和大数据技术的发展,数据挖掘已经成为了计算机科学领域的热门研究方向。数据挖掘是从大量的、不完全的、有噪声的、模糊的、随机的实际应用数据中,通过计算机科学、统计学、信息论等多学科交叉的方法,挖掘出有用信息和知识的过程。数据挖掘的目标是从数据中发现有

AI天才研究院 1600

HDU1213 How Many Tables 【标准并查集】

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

长风的专栏 1152

防火墙学习5---虚拟系统和跟系统通过路由表互访

虚拟系统与跟系统互访可分为虚拟系统访问根系统和跟系统访问虚拟系统。

weixin_48030849的博客 1031

动态规划法:n*m方格前进问题

在一个n*m的方格中,m为奇数,放置有n*m个数,方格中间的下方有一人,此人可按照正前方相临的五个方向(方格)前进但不能越出方格。人每走过一个方格必须取此方格中的数。要求找到一条从底到顶的路径,使其数相加之和为最大。输出和的最大值。 算法设计: 可以使用动态规划方法,从顶部开始,将第二排的每个数加上顶部第一排的最优解,将6排的问题缩小为5排的问题,然后重复该操作,直到底部最后一排,此时

Winifred_1997的博客 4675

【并查集】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

lammps模拟技巧:高熵合金势函数设置三种方法

大家好,我是小马老师。 本文继续介绍lammps模拟中的势函数设置方法。 在前面的文章中,介绍过高熵合金的建模:高熵合金建模 高熵合金包含的原子数较多,势函数的设置相对复杂,在平时一对一的咨询中,这种问题也相对较多。 下面介绍三种高熵合金势函数设置方法。 1.下载专用势函数 下面的网站包含了大多数原子的势函数: https://www.ctcms.nist.gov/potentials/ 如需下载包含Fe原子的势函数,直接点Fe: 出现势函数列表: 比如Al-Co-Cr-Fe-Ni就是高熵合金AlCoC

lammps_jiayou的博客 8962

HDU 1213 How Many Tables【并查集基础】

HDU 1213 How Many Tables 原题链接:vjudge传送门 题目大意: 给定n个人,m组关系(两人之间),关系可以传递,问总最终共有几组关系 eg:若a和b有关系,b和c有关系,则a,b,c都有关系,且为同一组关系 具体思路: 并查集 具体代码: #include<iostream> #include<cstdio> #include<algori...

指弹键盘哼民谣 389

华为OD新系统机试真题 - 操作历史管理器的撤销/重做能力

华为OD机试新系统真题【操作历史管理器的撤销/重做能力】,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。华为OD机试真题【操作历史管理器的撤销/重做能力】

qq_45776114的博客 864

CollisionLoss 设计与实现原理说明

文章摘要 CollisionLoss是一种用于自动驾驶轨迹规划的碰撞惩罚损失函数,其核心思想是用多个沿车身纵轴排列的圆盘来近似表示车辆(Oriented Bounding Box)。该设计通过圆盘间的距离计算实现碰撞检测,具有以下特点: 可微性:圆盘距离计算处处可微,便于梯度回传,而传统矩形碰撞检测(分离轴定理)不可微且计算复杂。 多圆盘设计:沿车身纵向排列多个圆盘能更精确地拟合细长车体,避免单圆盘过度膨胀导致的误报。 安全覆盖:圆盘半径经过数学推导,确保完全覆盖车体矩形,避免漏检(宁可保守)。 软惩罚机制

@bangbang的博客 94

【hdu1213】How Many Tables【并查集】

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 frien

cxllyg的专栏 3778

AUTOSAR进阶图解==>AUTOSAR_SWS_CANNetworkManagement

本文介绍了AUTOSAR架构中的CAN网络管理(CanNm)模块,主要内容包括: 模块概述:CanNm是协调CAN网络节点状态转换的基础组件,采用去中心化设计,通过周期性发送网络管理PDU保持网络活跃状态,支持网络唤醒、睡眠和部分网络功能。 架构设计:CanNm位于AUTOSAR中间层,连接上层通信管理器(ComM)和底层CAN接口(CanIf),包含状态管理、PDU处理和定时器管理等子组件。 状态机设计:定义了三种主要模式(总线睡眠、准备睡眠和网络模式)及其转换逻辑,网络模式又包含重复消息、正常操作和准备

一名留德华的,康德的信徒的,专注于汽车电子领域的博客 2040

hdu1213How many tables 并查集基础

How Many TablesTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3256    Accepted Submission(s): 1444Problem DescriptionToday is Ignatius' birthday. He invites a lot of friends. Now it's dinner time. Ig

独行闹市无人问,青灯剑影响素琴 695

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

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

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

HDU1213 How Many Tables【并查集】

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

独钓门前月 377

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

ACM-并查集之How Many Tables——hdu1213

ACM 并查集 How Many Tables hdu1213

继续激情,继续奋斗。 1604

HDU 1213 How Many Tables(并查集讲解)

       这是我写的第一道并查集的题,也应该是一道最简单的入门题了,所以就以这道题说下并查集,其实就是找关系,比如说这道题的题意就是有n个人聚餐,然后他们不一定都互相认识,如果a认识b,b认识c,那么就让他们仨坐一桌,再如果c认识d,d认识e,那么就让这三个人另外坐一桌,所以就是有关系的就坐一桌,然后问需要多少张桌子(忽略每张桌子能坐多少人)。        那么并查集就分为并和查两个过程, ...

Charles_Zaqdt的博客 769

HDU - 1213 How Many Tables 【并查集】

题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1213 题意 给出N个人 M对关系 找出共有几对连通块 思路 并查集 AC代码 #include <cstdio> #include <cstring> #include <ctype.h> #includ...

banshen0201的博客 175

HDU1213 How Many Tables(基础并查集)

HDU1213 How Many Tables(基础并查集) 链接:题目Time Limit: 1000ms Memory Limit: 32768KB Description Today is Ignatius’ birthday. He invites a lot of friends. Now it’s dinner time. Ignatius wants to know how m

Minecode的博客 508

Hdu1213 How Many Tables【并查集】

http://acm.hdu.edu.cn/showproblem.php?pid=1213 题目大意:给出一些关系,求有几个集合。 “OneimportantruleforthisproblemisthatifItellyouAknowsB,andBknowsC,thatmeansA,B,Cknoweachother,so...

bantengbang8949的博客 125

HDU 1213 How Many Tables(并查集)

传送门:HDU 1213

一个写程序的 748

HDU - 1213 How Many Tables [并查集]

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

182

HDU1213-How Many Tables 并查集

HDU1213-How Many Tables,并查集算法,算出根的个数就是答案了

P_rogrammer的专栏 620

hdu1213-How Many Tables(并查集)

并查集最基本的一道题。 How Many Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 53136 Accepted Submission(s): 26397 Problem Description Today is...

小麦面包 428

hdu1213 - How Many Tables (基础并查集)

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

ITCTO-疯男的优快云博客 603
上一篇: HDU-4310 Hero (贪心)
下一篇: HDU-1455  Sticks (DFS+剪枝)
进阶的萌新
博客等级 码龄9年 5粉丝 29原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值