hdu 1213 How Many Tables(并查集练习)
题目链接:hdu1213
赤裸裸的并查集。。。。。水题一个。。。。
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
#define MAXN 10
using namespace std;
int father[1005];
void build(int n)
{
for(int i = 0 ; i <= n ; i ++)
father[i] = i;
}
int find(int x)
{
if(x != father[x])
{
father[x] = find(father[x]);
}
return father[x];
}
void Union(int x,int y)
{
x = find(x);
y = find(y);
if(x == y) return;
father[y] = x;
}
int main()
{
int T,n,m,i,x,y;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
build(n);
while(m--)
{
scanf("%d%d",&x,&y);
Union(x,y);
}
int ans = 0;
for(i = 1 ; i <= n ; i ++)
if(father[i] == i) ans ++;
printf("%d\n",ans);
}
return 0;
}
hdu 1213 How Many Tables(并查集练习)的更多相关文章
- 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 果然是需要我陪跑T T,禽兽工作人员还不让,哼,但还是陪跑了~ 啊,还有呀,明天校运会终于不用去了~耶耶耶 ...
- HDU 1213 How Many Tables(并查集,简单)
题解:1 2,2 3,4 5,是朋友,所以可以坐一起,求最小的桌子数,那就是2个,因为1 2 3坐一桌,4 5坐一桌.简单的并查集应用,但注意题意是从1到n的,所以要减1. 代码: #include ...
- HDU 1213 How Many Tables (并查集,常规)
并查集基本知识看:http://blog.csdn.net/dellaserss/article/details/7724401 题意:假设一张桌子可坐无限多人,小明准备邀请一些朋友来,所有有关系的朋 ...
- HDU 1213 How Many Tables 并查集 寻找不同集合的个数
题目大意:有n个人 m行数据,每行数据给出两个数A B,代表A-B认识,如果A-B B-C认识则A-C认识,认识的人可以做一个桌子,问最少需要多少个桌子. 题目思路:利用并查集对相互认识的人进行集合的 ...
- hdu 1213 求连通分量(并查集模板题)
求连通分量 Sample Input2 //T5 3 //n m1 2// u v2 34 5 5 12 5 Sample Output24 # include <iostream> # ...
- 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 题意: 这个问题的一个重要规则是,如果我告诉你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 题目链接: http://acm.hust.edu.cn/vjudge/contest/123393#problem/C Description Today is Ig ...
随机推荐
- OC第四课
主要内容:NSString.NSArray.NSNumber 一.苹果公司的帮助文档(API) 学会查看API对于后续的编程有很好的帮助 进入方法: Xcode ->Help -> Doc ...
- javascript7
语句:条件,循环,跳转, 表达式语句,复合语句和空语句,声明语句,var,function,条件语句,switch,循环,标签语句,break语句,continue语句,return语句,throw语 ...
- 企业办公即时通信软件TeamTalk
TeamTalk 一键部署方案:TTAutoDeploy TeamTalk 整套服务提供模块部署脚本和一键部署方案,主要模块有JDK,NGINX,PHP,PERCONA(MYSQL), REDIS ...
- weblogic生产、开发模式互转
生产模式与开发模式转换: 1.生产模式-->开发模式 将%DOMAIN_HOME%\config\config.xml文件中<production-mode-enabled> ...
- [译]Java 设计模式之原型
(文章翻译自Java Design Pattern: Prototype) 原型模式用于当当非常相似的对象频繁被需要的时候.原型模式克隆了对象并且设置变化的特征.这种方式会消耗更少的资源.考虑下为什么 ...
- IIS 5.x/6.0/7.0 和 ASP.NET
原文:IIS 5.x/6.0/7.0 和 ASP.NET 本文主要介绍 3 个主要的 IIS 版本各自对 Web 请求的不同处理方式. 本文内容 IIS 5.x 和 ASP.NET IIS 6.0 和 ...
- SQL SERVER – Import CSV File Into SQL Server Using Bulk Insert – Load Comma Delimited File Into SQL Server
CSV stands for Comma Separated Values, sometimes also called Comma Delimited Values. Create TestTabl ...
- SVN服务器搭建(3)
转自:http://www.cnblogs.com/xiaobaihome/archive/2012/03/20/2408089.html vs 2013 svn插件:http://www.visua ...
- shell脚本中执行另一个shell脚本
分类: 可以在一个shell脚本中执行另一个shell脚本(或非可执行文件,主要用于取得一些变量的值),方法是: . 文件名(包括路径) 或 变量=文件名(包括路径) . $变量 注意,圆点后面有 ...
- Ibatis配置存储过程xml文件案例
-- <parameterMaps> <!--注意:parameterMap中的参数个数和顺序要和ProcGetPersonByName存储过程中的一致--> <para ...