题目链接: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(并查集练习)的更多相关文章

  1. HDU 1213 - How Many Tables - [并查集模板题]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1213 Today is Ignatius' birthday. He invites a lot of ...

  2. HDU 1213 How Many Tables 并查集 水~

    http://acm.hdu.edu.cn/showproblem.php?pid=1213 果然是需要我陪跑T T,禽兽工作人员还不让,哼,但还是陪跑了~ 啊,还有呀,明天校运会终于不用去了~耶耶耶 ...

  3. HDU 1213 How Many Tables(并查集,简单)

    题解:1 2,2 3,4 5,是朋友,所以可以坐一起,求最小的桌子数,那就是2个,因为1 2 3坐一桌,4 5坐一桌.简单的并查集应用,但注意题意是从1到n的,所以要减1. 代码: #include ...

  4. HDU 1213 How Many Tables (并查集,常规)

    并查集基本知识看:http://blog.csdn.net/dellaserss/article/details/7724401 题意:假设一张桌子可坐无限多人,小明准备邀请一些朋友来,所有有关系的朋 ...

  5. HDU 1213 How Many Tables 并查集 寻找不同集合的个数

    题目大意:有n个人 m行数据,每行数据给出两个数A B,代表A-B认识,如果A-B B-C认识则A-C认识,认识的人可以做一个桌子,问最少需要多少个桌子. 题目思路:利用并查集对相互认识的人进行集合的 ...

  6. hdu 1213 求连通分量(并查集模板题)

    求连通分量 Sample Input2 //T5 3 //n m1 2// u v2 34 5 5 12 5 Sample Output24 # include <iostream> # ...

  7. HDU 1213 How Many Tables(模板——并查集)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1213 Problem Description Today is Ignatius' birthday ...

  8. HDU 1213 How Many Tables(并查集模板)

    http://acm.hdu.edu.cn/showproblem.php?pid=1213 题意: 这个问题的一个重要规则是,如果我告诉你A知道B,B知道C,这意味着A,B,C知道对方,所以他们可以 ...

  9. HDU - 1213 How Many Tables 【并查集】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1213 题意 给出N个人 M对关系 找出共有几对连通块 思路 并查集 AC代码 #include < ...

  10. HDU 1213 How Many Tables (并查集)

    How Many Tables 题目链接: http://acm.hust.edu.cn/vjudge/contest/123393#problem/C Description Today is Ig ...

随机推荐

  1. MVC 5 Web编程2 -- URL映射

    ASP.NET MVC 5 Web编程2 -- URL映射(路由原理) 2015-02-12 08:50 by hangwei, 704 阅读, 5 评论, 收藏, 编辑 本章将讲述ASP.NET M ...

  2. CKPlayer从Cookie里读取上次播放记录的一个demo

    <!DOCTYPE html><html><head> <meta http-equiv="Content-Type" content=& ...

  3. Linux中iptables设置详细

    无论如何,iptables是一个需要特别谨慎设置的东西,万一服务器不在你身边,而你贸然设置导致无法SSH,那就等着被老板骂吧,呵呵... 一下内容是为了防止这种情况发生而写的,当然很初级,不过一般服务 ...

  4. git上自然框架源码

    [自然框架]终于把源码弄到git上吗了 2015-02-02 14:38 by 金色海洋(jyk)阳光男孩, 183 阅读, 6 评论, 收藏, 编辑 好久没写博客了,发现又从左面的排名里掉出去了. ...

  5. hdu149850 years, 50 colors (多个最小顶点覆盖)

    50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...

  6. hdu oj1102 Constructing Roads(最小生成树)

    Constructing Roads Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  7. Oracle并行查询出错

    1.错误描写叙述 ORA-12801: 并行查询服务器P007中发出错误信号 ORA-01722:无效数字 12801.00000 -"error signaled in parallel ...

  8. DDD 应对具体业务场景,Domain Model 重新设计

    DDD 应对具体业务场景,Domain Model 重新设计 写在前面 上联:no zuo no die why you try 下联:no try no high give me five 横批: ...

  9. DDD(领域驱动设计)应对具体业务场景,如何聚焦 Domain Model(领域模型)?

    DDD(领域驱动设计)应对具体业务场景,如何聚焦 Domain Model(领域模型)? 阅读目录: 问题根源是什么? <领域驱动设计-软件核心复杂性应对之道>分层概念 Repositor ...

  10. iOS基础 - 文本属性Attributes

    NSKernAttributeName: 调整字句 kerning 字句调整 NSFontAttributeName : [UIFont systemFontOfSize:_fontSize] 设置字 ...