链接:

http://poj.org/problem?id=1611

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

代码:

#include<stdio.h>
#include<string.h>
#include<stdlib.h> #define N 30005 int a[N];
int n, m; int Find(int x)
{
if(a[x]!=x)
a[x] = Find(a[x]);
return a[x];
} int main()
{ while(scanf("%d%d", &n, &m), n+m)
{
int p, px, py, s, x, y; for(int i=; i<=n; i++)
a[i] = i; for(int i=; i<m; i++)
{
scanf("%d%d", &s, &x); for(int j=; j<s; j++)
{
scanf("%d", &y); px = Find(x);
py = Find(y);
if(px!=py)
a[py] = px;
}
}
int sum=;
p = Find(); for(int i=; i<n; i++)
if(Find(i)==p)
sum++; printf("%d\n", sum); }
return ;
}

(并查集)The Suspects --POJ --1611的更多相关文章

  1. C - The Suspects POJ - 1611(并查集)

    Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized ...

  2. B - The Suspects -poj 1611

    病毒扩散问题,SARS病毒最初感染了一个人就是0号可疑体,现在有N个学生,和M个团队,只要团队里面有一个是可疑体,那么整个团队都是可疑体,问最终有多少个人需要隔离... 再简单不过的并查集,只需要不断 ...

  3. The Suspects POJ 1611

    The Suspects Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, w ...

  4. 并查集判树 poj 1308

    例题: poj 1308 题目大意比较简单,对任意两个点,有且仅有一条道路,也就是一棵树. 题解:一棵树中,肯定是不能有环的,而且只能由一个根节点.(没认真读题,只知道在那里判环....),所以这个题 ...

  5. kuangbin 并查集

    A : Wireless Network  POJ - 2236 题意:并查集,可以有查询和修复操作 题解:并查集 #include<iostream> #include<cstdi ...

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

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

  7. 并查集 (poj 1611 The Suspects)

    原题链接:http://poj.org/problem?id=1611 简单记录下并查集的模板 #include <cstdio> #include <iostream> #i ...

  8. [并查集] POJ 1611 The Suspects

    The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 35206   Accepted: 17097 De ...

  9. poj 1611:The Suspects(并查集,经典题)

    The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 21472   Accepted: 10393 De ...

随机推荐

  1. How a non-windowed component can receive messages from Windows

    Why do it? Sometimes we need a non-windowed component (i.e. one that isn't derived fromTWinControl) ...

  2. delphi 中判断对象是否具备某一属性

    Uses   TypInfo;         {$R   *.dfm}         procedure   TForm1.Button1Click(Sender:   TObject);     ...

  3. Spring 集成Hibernate的三种方式

    首先把hibernate的配置文件hibernate.cfg.xml放入spring的src目录下,并且为了便于测试导入了一个实体类Student.java以及它的Student.hbm.xml文件 ...

  4. spring中的BeanFactory和FactoryBean的区别与联系

    首先,这俩都是个接口… 实现 BeanFactory 接口的类表明此类是一个工厂,作用就是配置.新建.管理 各种Bean. 而 实现 FactoryBean 的类表明此类也是一个Bean,类型为工厂B ...

  5. k8s 问题

    kubelet: Orphaned pod "4db449f0-4eaf-11e8-94ab-90b8d042b91a" found, but volume paths are s ...

  6. 微擎系统 微信支付 get_brand_wcpay_request:fail

    支付授权目录问题,有一个是域名加app的

  7. Jakarta项目

    Jakarta项目是ASF(The Apache Software Foundation)的一部分.ASF是一个非赢利组织,她鼓励基于开放的软件许可下进行合作.注重实效的开发,并提供各个领域的高质量软 ...

  8. inner join和outer join

    内连接           只连接匹配的行 左外连接        包含左边表的全部行(不管右边的表中是否存在与它们匹配的行),以及右边表中全部匹配的行 A left join B等价于A left ...

  9. 早上突然看明白 shader和材质球的关系

    计算机的世界不外乎 指令+数据 shader即Gpu指令,材质即数据

  10. 在Eclipse中配置Maven插件

    --------------------------siwuxie095                                     在 Eclipse 中配置 Maven 插件     ...