链接:

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. Matlab学以致用 - 曲线拟合

    曲线拟合 使用Matlab自带的polyfit函数,可以很方便地根据现有样本数据进行多项式曲线拟合,为了有直观感受,先上例程,如下所示: x = -:; % 样本数据x坐标 y = *x.^ + *x ...

  2. sessionStorage和localStorage

    html5中的Web Storage包括了两种存储方式:sessionStorage和localStorage. sessionStorage用于本地存储一个会话(session)中的数据,这些数据只 ...

  3. jenkins 自动构建gitlab项目

    安装的plugin: - kubernetes:1.7.1    - workflow-aggregator:2.5    - workflow-job:2.21    - credentials-b ...

  4. docker 配置远程访问证书验证

    centos7 生成证书 工具:openssl #cd /etc/docker   (docker的证书一般放这) #openssl genrsa -aes256 -passout pass:密码   ...

  5. sql server 数据库学习

    http://m.blog.csdn.net/anxpp/article/details/51295020

  6. Python3 enumerate() 函数

    Python3 enumerate() 函数  Python3 内置函数 描述 enumerate() 函数用于将一个可遍历的数据对象(如列表.元组或字符串)组合为一个索引序列,同时列出数据和数据下标 ...

  7. TZOJ 5279 马拉松比赛(广搜)

    描述 有一块矩形的海域,其中有陆地也有海洋,这块海域是CSUFT_ACM集训队的训练基地,这一天,昌神说要集训队的队员不能总是训练,于是昌神提出了中南林ACM集训队第一场环陆马拉松比赛,顾名思义就是围 ...

  8. 【校招面试 之 C/C++】第8题 C++中的静态绑定与动态绑定

    转自:https://blog.csdn.net/chgaowei/article/details/6427731   做了部分修改 为了支持c++的多态性,才用了动态绑定和静态绑定.理解他们的区别有 ...

  9. MVC仓储类Repository

    接口: using Common; using System; using System.Collections; using System.Collections.Generic; using Sy ...

  10. SoapUI Script Library

    Environment Get active environment via groovy script log.info testRunner.testCase.testSuite.project. ...