hdu-1213-How Many Tables
How Many Tables
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 25116 Accepted Submission(s): 12523
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.
5 3
1 2
2 3
4 5
5 1
2 5
4
题目大意:水题计算最后的集合个数。
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1213
代码:
#include <iostream>
using namespace std;
int f[];
int find(int n)
{
if(n!=f[n])
f[n]=find(f[n]);
return f[n];
}
int main()
{ int t,n,m;
cin>>t;
while(t--)
{
cin>>n>>m;
for(int i=;i<=n;i++)
f[i]=i;
int a,b;
for(int i=;i<m;i++)
{
cin>>a>>b;
int a1=find(a);
int b1=find(b);
f[a1]=b1;
}
int t1=;
for(int i=;i<=n;i++)
if(find(i)==i)
t1++;
cout<<t1<<endl;
} }
hdu-1213-How Many Tables的更多相关文章
- 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 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 有关系(直接或间接均可)的人就坐在一张桌子,我们要统计的是最少需要的桌子数. 并查集的入门题,什 ...
- 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 并查集 水~
http://acm.hdu.edu.cn/showproblem.php?pid=1213 果然是需要我陪跑T T,禽兽工作人员还不让,哼,但还是陪跑了~ 啊,还有呀,明天校运会终于不用去了~耶耶耶 ...
- HDU 1213 How Many Tables(并查集)
传送门 Description Today is Ignatius' birthday. He invites a lot of friends. Now it's dinner time. Igna ...
- HDU 1213 How Many Tables (并查集)
How Many Tables 题目链接: http://acm.hust.edu.cn/vjudge/contest/123393#problem/C Description Today is Ig ...
- HDU 1213 How Many Tables(并查集裸题)
Problem Description Today is Ignatius' birthday. He invites a lot of friends. Now it's dinner time. ...
随机推荐
- Fiddler实战深入研究(二)
Fiddler实战深入研究(二) 阅读目录 Fiddler不能捕获chrome的session的设置 理解数据包统计 请求重定向(AutoResponder) Composer选项卡 Filters选 ...
- h5原生拖拽
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- html5 浏览器端数据库
为什么使用浏览器端数据库:随着浏览器的处理能力不断增强,越来越多的网站开始考虑,将大量数据储存在客户端,这样可以减少用户等待从服务器获取数据的时间. 一.localStorage — 本地存储 可 ...
- Java基础,输入输出
package hanqi.test; import java.io.File; import java.io.IOException; public class Test02 { public st ...
- Pycharm远程调试
1.在pycharm的安装目录中找到pycharm-debug.egg,将其拷贝到目标主机的/usr/lib/python2.7/dist-packages目录下: 执行: sudo easy_ins ...
- C# 集合类 :(Array、 Arraylist、List、Hashtable、Dictionary、Stack、Queue)
我们用的比较多的非泛型集合类主要有 ArrayList类 和 HashTable类.我们经常用HashTable 来存储将要写入到数据库或者返回的信息,在这之间要不断的进行类型的转化,增加了系统装箱和 ...
- Project简介
Microsoft Project (Project)是一个国际上享有盛誉的通用的项目管理工具软件,凝集了许多成熟的项目管理现代理论和方法,可以帮助项目管理者实现时间.资源.成本的计划.控制,协助项目 ...
- 搭建PHP开发环境
通过两种方式搭建PHP开发环境,而这种开发环境实际是:Apache+MySQL+PHP. 第一种: 通过套件来安装和配置php开发环境. Apache+MySQL+PHP开发环境的搭建(一) 第二种 ...
- javascript 入门——this属性的理解!
JavaScript中函数的this对象是函数在执行时所处的作用域(例:当在网页的全局作用域中调用函数时,this对象引用的就是window). 例: window.color = "red ...
- Android Studio导入项目非常慢的解决办法
问题 Android Studio目前已经更新到2.0 Preview 6了,作为Google大力推崇的开发工具,相对于Eclipse ADT有着不可比拟的优势.然而在实际使用时,依然有不少不爽的地方 ...