hdu 1213
简单并查集
#include <cstdio>
#include <cstring>
#define maxn 30005
int fa[maxn],ans[maxn],n,m; int findd( int x )
{
return fa[x] == x ? x : fa[x] = findd(fa[x]);
}
int main()
{
//freopen("d://in.txt", "r", stdin);
int t;
scanf("%d", &t);
while(t--)
{
memset(ans, 0, sizeof(ans));
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i)
fa[i] = i;
for (int i = 0; i < m; ++i)
{
int x, y, u, v;
scanf("%d%d", &u, &v);
x = findd(u);
y = findd(v);
if (x != y)
fa[x] = y;
}
for (int i = 1; i <= n; ++i)
ans[findd(i)]++;
int _max= 0;
for (int i = 1; i <= n; ++i)
{
if(ans[i])
_max++;
}
printf("%d\n", _max);
}
return 0;
}
hdu 1213的更多相关文章
- 【并查集】模板 + 【HDU 1213、HDU 1232、POJ 2236、POJ 1703】例题详解
不想看模板,想直接看题目的请戳下面目录: 目录: HDU 1213 How Many Tables[传送门] HDU 1232 畅通工程 [传送门] POJ 2236 Wireless Network ...
- 并查集---体会以及模板&&How Many Tables - HDU 1213
定义&&概念: 啥是并查集,就是将所有有相关性的元素放在一个集合里面,整体形成一个树型结构,它支持合并操作,但却不支持删除操作 实现步骤:(1)初始化,将所有节点的父亲节点都设置为自己 ...
- 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 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 题意: 这个问题的一个重要规则是,如果我告诉你A知道B,B知道C,这意味着A,B,C知道对方,所以他们可以 ...
- (并查集)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(裸并查集)(无变形)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1213 How Many Tables Time Limit: 2000/1000 MS (Java/ ...
- 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 题意 给出N个人 M对关系 找出共有几对连通块 思路 并查集 AC代码 #include < ...
随机推荐
- HDOJ2019数列有序!
数列有序! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- 修改msconfig->引导->高级选项-》最大内存为512M
本来想开机提速的!手贱 把 最大内存设置成了512M 结果开机悲剧了,启用了微软的自动修复也不能解决问题!最后是WIN7 PE系统下直接修复boot结果了.遇到这种问题的朋友们可以试试喔
- jQuery之手势密码
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- BLK-MD-BC04-B蓝牙模块开发说明
BLK-MD-BC04-B蓝牙模块开发说明 日期:2011-9-24 浏览次数:4178 BLK-MD-BC04-B蓝牙通信模块, BLK-MD-BC04-B蓝牙通信模块 为本公司自主开发的智 ...
- LeftOuterJoin和OuterApply性能比较(转)
建立测试环境: 建立一个表Department和Employee,并向Department插入50W条记录,向Employee插入200W条记录, 我们就拿[统计DepartmentID 从15000 ...
- docker & nodejs & mongodb
Nodejs 应用简单的访问Mongodb 部署至Docker 1.本地简单的写能运行起来的一个nodejs (demo可写的更简单 一个post一个get即可) schemas user.js v ...
- (poj 3177) Redundant Paths
题目链接 :http://poj.org/problem?id=3177 Description In order to <= F <= ,) grazing fields (which ...
- 印象笔记无法同步问题解决 Unable to send HTTP request: 12029
问题 今天突然发现本地软件不能访问网络. 包括: 印象笔记无法同步, 搜狗输入法无法登陆. 但其它上网正常. 思路及解决过程 因为chrome上网 ,qq上网均正常. 且同事可以正常使用. 推测是本地 ...
- 滑动选择日期(基于sui-mobile的移动端)
$(page).on('touchmove','#touchMoveTime',function (event) { touchMove(event); }); scrollBarInit(); // ...
- 获取客户端访问的ip地址
function real_ip() { static $realip = NULL; if ($realip !== NULL) { return $realip; } if (isset($_SE ...