hdu 1213 How Many Tables 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1213
有关系(直接或间接均可)的人就坐在一张桌子,我们要统计的是最少需要的桌子数。
并查集的入门题,什么优化都无用到就可以直接过。实质上就是统计总共有多少个不相交的集合。比较可恶的是,题目中 There will be a blank line between two cases 是骗人的!!!
#include <iostream>
using namespace std; const int maxn = + ;
int p[maxn], rank[maxn]; int find(int x)
{
while (x != p[x])
x = p[x];
return x;
} void merge(int i, int j)
{
int x = find(i);
int y = find(j);
if (x > y)
p[y] = x;
else
p[x] = y;
} int main()
{
int a, b, i, t, m, n, refusals;
while (scanf("%d", &t) != EOF)
{
while (t--)
{
scanf("%d%d", &n, &m);
for (i = ; i <= n; i++)
p[i] = i;
for (i = ; i < m; i++)
{
scanf("%d%d", &a, &b);
merge(a, b);
}
for (refusals = , i = ; i <= n; i++)
if (p[i] == i)
refusals++;
printf("%d\n", refusals);
}
}
return ;
}
hdu 1213 How Many Tables 解题报告的更多相关文章
- 【九度OJ】题目1445:How Many Tables 解题报告
[九度OJ]题目1445:How Many Tables 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1445 题目描述: ...
- 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 Problem Description Today is Ignatius' birthday. ...
- hdu 1050 Moving Tables 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1050 这道题目隔了很久才做出来的.一开始把判断走廊有重叠的算法都想错了.以为重叠只要满足,下一次mov ...
- 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知道对方,所以他们可以 ...
- HDU - 1213 How Many Tables 【并查集】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1213 题意 给出N个人 M对关系 找出共有几对连通块 思路 并查集 AC代码 #include < ...
- HDU 1213 How Many Tables【并查集】
解题思路:和畅通工程类似,问最后还剩下几个不连通的区域. How Many Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...
随机推荐
- 【POJ 2243】Knight Moves
题 Description A friend of you is doing research on the Traveling Knight Problem (TKP) where you are ...
- SSH配置文件和SSM配置文件的写法
一.SSH配置文件的写法(XML版本) <util:properties id="jdbc" location="classpath:db.properties&q ...
- BZOJ1452 [JSOI2009]Count
Description Input Output Sample Input Sample Output 1 2 HINT 正解:二维树状数组 解题报告: 这是一道送肉题.二维树状数组直接维护每种颜色的 ...
- BZOJ1113 海报PLA
好像是很古老的题?现在BZOJ上找不到该题,所以没有提交. 1113: [Poi2008]海报PLA Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 8 ...
- c++实现gray code(格雷码)
今天别人问的一道题,强调用分治法实现 =.= 百度了一下格雷码,然后写了一下. 关于格雷码大家看百度的吧,特别详细,贴个图: 代码如下(header_file.h是我自己写的一个头文件,包括常见的ve ...
- ubuntu 12.04 server + OPENACS(TR069)安装配置日记
1. 有两个叫openacs的, openacs.org下的不是 2. 严格匹配版本:luo@bogon:~$ ls jboss-4.2.3.GA-jdk6.zip jdk-6u41-linux-i ...
- POJ1459Power Network(dinic模板)
Power Network Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 25832 Accepted: 13481 D ...
- javascript判断文件大小
<input type="file" id="fileName" name ="fileName" onchange="Ge ...
- JS Resizable Panel 练习
Resizable Panel HTML <!doctype html> <html> <head> <title>Resizable Panel< ...
- mouseover和mouseout闪烁问题
在父级元素上注册了mouseover和mouseout事件后,当鼠标移动到子元素上时,会触发父级的mouseout和mouseover事件,反复触发,形成闪烁. 原因: 一种是由于冒泡,子级的mous ...