链接:

http://acm.hdu.edu.cn/showproblem.php?pid=1213

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#problem/C

代码:

#include<stdio.h>
#include<queue>
#include<stack>
#include<string.h>
using namespace std; #define maxn 1005
#define oo 0xfffffff int n, m;
int f[maxn]; int Find(int x)
{
if(x!=f[x])
f[x]=Find(f[x]);
return f[x];
} int main()
{
int t, i;
scanf("%d", &t);
while(t--)
{
int a, b, fa, fb;
scanf("%d%d", &n, &m); for(i=; i<=n; i++)
f[i]=i; for(i=; i<=m; i++)
{
scanf("%d%d", &a, &b);
fa=Find(a), fb=Find(b); if(fa!=fb)
f[fa]=fb;
} int sum=; for(i=; i<=n; i++)
{
if(f[i]==i)
sum++;
} printf("%d\n", sum);
}
return ;
}

(并查集)How Many Tables -- HDU --1213的更多相关文章

  1. 【并查集】模板 + 【HDU 1213、HDU 1232、POJ 2236、POJ 1703】例题详解

    不想看模板,想直接看题目的请戳下面目录: 目录: HDU 1213 How Many Tables[传送门] HDU 1232 畅通工程 [传送门] POJ 2236 Wireless Network ...

  2. 并查集---体会以及模板&&How Many Tables - HDU 1213

    定义&&概念: 啥是并查集,就是将所有有相关性的元素放在一个集合里面,整体形成一个树型结构,它支持合并操作,但却不支持删除操作 实现步骤:(1)初始化,将所有节点的父亲节点都设置为自己 ...

  3. 【并查集专题】【HDU】

    PS:做到第四题才发现 2,3题的路径压缩等于没写 How Many Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65 ...

  4. (并查集)POJ 1308 & HDU 1325

    一开始以为两道题是一样的,POJ的过了直接用相同代码把HDU的交了,结果就悲剧了.最后发现HDU的没有考虑入度不能大于一. 题意:用树的定义来 判断吧,无环,n个结点最多有n-1条边,不然就会有环.只 ...

  5. [并查集] How Many Tables

    题目描述 Today is Ignatius' birthday. He invites a lot of friends. Now it's dinner time. Ignatius wants ...

  6. How Many Tables HDU - 1213

    #include<iostream> using namespace std; ; int p[N]; int find(int x) { if(p[x]!=x) p[x]=find(p[ ...

  7. [kuangbin带你飞]专题五 并查集

    并查集的介绍可以看下https://www.cnblogs.com/jkzr/p/10290488.html A - Wireless Network POJ - 2236 An earthquake ...

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

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

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

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

随机推荐

  1. UGUI双击事件

    经测试在Android.ios平台下无效 using UnityEngine; using UnityEngine.EventSystems; using System.Collections; us ...

  2. 【转载】 Java并发编程:深入剖析ThreadLocal

    原文链接:http://www.cnblogs.com/dolphin0520/p/3920407.html感谢作者的辛苦总结! Java并发编程:深入剖析ThreadLocal 想必很多朋友对Thr ...

  3. zookeeper 初步学习

    配置文件: tickTime:这个时间是作为 Zookeeper 服务器之间或客户端与服务器之间维持心跳的时间间隔,也就是每个 tickTime 时间就会发送一个心跳. dataDir:顾名思义就是 ...

  4. session会话管理,与过滤器使用,访问控制

    1 用户登录,是否注册用户,在登录处理页面进行用户验证,创建session保存用户名和密码 2否,进入用户注册页面 3是,系统保存该用户的登录信息 4进入要访问的页面 5用户直接访问某个页面, 6系统 ...

  5. 文件和Variant的转换

    function FileToVariant(FileName: String): OleVariant; var   AStream: TFileStream;   MyBuffer: Pointe ...

  6. dowhile

    public class TestDoWhile { /**do while 至少执行一次 先斩后奏 * 测试dowhile */ public static void main(String[] a ...

  7. rabbitMQ 常用命令

    启动监控管理器:rabbitmq-plugins enable rabbitmq_management 关闭监控管理器:rabbitmq-plugins disable rabbitmq_manage ...

  8. css写三角形

    #triangle-up {    width: 0;    height: 0;    border-left: 50px solid transparent;    border-right: 5 ...

  9. Oracle完全卸载

      停用oracle服务:进入计算机管理,在服务中,找到oracle开头的所有服务,右击选择停止   在开始菜单中,找到Universal Installer,运行Oracle Universal I ...

  10. 6-Qt给父widget加上styleSheet(添加背景图)而不改变子widget的styleSheet的方法

    Qt给父widget加上styleSheet(添加背景图)而不改变子widget的styleSheet的方法 比如用stylesheet给widget加背景图,可以用qt designer修改ui文件 ...