How Many Tables HDU - 1213
#include<iostream>
using namespace std;
const int N=;
int p[N];
int find(int x)
{
if(p[x]!=x)
p[x]=find(p[x]);
return p[x];
}
int main()
{
int t;
int n,m;
cin>>t;
while(t--)
{
cin>>n>>m;
for(int i=;i<=n;i++)
p[i]=i;
while(m--)
{
int a,b;
cin>>a>>b;
int pa=find(a);
int pb=find(b);
if(pa!=pb)
p[pa]=pb;
}
int res=;
for(int i=;i<=n;i++)
if(p[i]==i)
res++;
cout<<res<<endl;
}
return ;
}
How Many Tables HDU - 1213的更多相关文章
- 并查集---体会以及模板&&How Many Tables - HDU 1213
定义&&概念: 啥是并查集,就是将所有有相关性的元素放在一个集合里面,整体形成一个树型结构,它支持合并操作,但却不支持删除操作 实现步骤:(1)初始化,将所有节点的父亲节点都设置为自己 ...
- (并查集)How Many Tables -- HDU --1213
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1213 http://acm.hust.edu.cn/vjudge/contest/view.action ...
- 【并查集】模板 + 【HDU 1213、HDU 1232、POJ 2236、POJ 1703】例题详解
不想看模板,想直接看题目的请戳下面目录: 目录: HDU 1213 How Many Tables[传送门] HDU 1232 畅通工程 [传送门] POJ 2236 Wireless Network ...
- HDU 1213 How Many Tables(模板——并查集)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1213 Problem Description Today is Ignatius' birthday ...
- HDU 1213 - How Many Tables - [并查集模板题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1213 Today is Ignatius' birthday. He invites a lot of ...
- hdu 1213 How Many Tables(并查集算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1213 How Many Tables Time Limit: 2000/1000 MS (Java/O ...
- hdu 1213 How Many Tables 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1213 有关系(直接或间接均可)的人就坐在一张桌子,我们要统计的是最少需要的桌子数. 并查集的入门题,什 ...
- HDU 1213 How Many Tables(并查集模板)
http://acm.hdu.edu.cn/showproblem.php?pid=1213 题意: 这个问题的一个重要规则是,如果我告诉你A知道B,B知道C,这意味着A,B,C知道对方,所以他们可以 ...
- HDU - 1213 How Many Tables 【并查集】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1213 题意 给出N个人 M对关系 找出共有几对连通块 思路 并查集 AC代码 #include < ...
随机推荐
- Go语言实现:【剑指offer】字符串的排列
该题目来源于牛客网<剑指offer>专题. 输入一个字符串,按字典序打印出该字符串中字符的所有排列.例如输入字符串abc,则打印出由字符a,b,c所能排列出来的所有字符串abc,acb,b ...
- golang搭建一个简单的web服务器
package main import ( "io/ioutil" "log" "net/http" ) func main() { htt ...
- ubuntu下怎么配置/查看串口-minicom工具
一.安装minicom工具: 可直接使用命令sudo apt-get install minicom来完成安装 上面的截图因为检测到我已经安装过了. 二.通过minicom工具配置串口: 1.启动mi ...
- k8s系列---yaml文件格式
https://www.bejson.com/validators/yaml_editor/ yaml文件大致格式解析,通过上面这个解析网站,可以看到yaml文件解析的格式长什么样,如果知道字典和列表 ...
- light oj1028 - Trailing Zeroes (I)
1028 - Trailing Zeroes (I) We know what a base of a number is and what the properties are. For exa ...
- 创建PyCharm工程
- mysql设置编码格式--支持中文
创建table的时候就使用utf8编码 在每次创建表的时候都在最后加上 character set = utf8就可以很好的支持中文 create table xxx ( id int auto_in ...
- [MySQL]mysql binlog回滚数据
1.先开启binlog log-bin = /var/log/mysql/mysql_bin #binlog日志文件,以mysql_bin开头,六个数字结尾的文件:mysql_bin.000001,并 ...
- Python+PyQT5的子线程更新UI界面的实例《新手必学》
今天小编就为大家分享一篇Python+PyQT5的子线程更新UI界面的实例,具有很好的参考价值,希望对大家有所帮助.一起跟随小编过来看看吧子线程里是不能更新UI界面的,在移动端方面.Android的U ...
- Git命令行操作方法
1.GitHub上创建一个Repositories(仓库),并复制仓库地址