链接:

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 to Pronounce the I in ING

    How to Pronounce the I in ING Share Tweet Share Tagged With: ING Verbs The I in ING is the IH as in ...

  2. LitJson JavaScriptSerializer

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  3. 作业:WordCount--实现字符数,单词数,行数的统计

    1. Gitee 地址 https://gitee.com/fyxiaobai/wordcount 2. PSP表格 PSP2.1 PSP阶段 预估耗时 (分钟) 实际耗时 (分钟) Planning ...

  4. DataFrame查增改删

    DataFrame查增改删 查 Read 类list/ndarray数据访问方式 dates = pd.date_range(',periods=10) dates df = pd.DataFrame ...

  5. 疯狂JAVA——第七章 java基础类库

    System类代表当前java程序的运行平台,程序不能创建System类的对象,System类提供了一些类变量和类方法,允许直接通过System类来调用这些类变量和类方法.

  6. select 1 与 select null (转)

    1.Select 1 在这里我主要讨论的有以下几个select 语句: table表是一个数据表,假设表的行数为10行,以下同. 1:select  1 from table 2:select cou ...

  7. pre换行段落间距

    <!DOCTYPE html><html><head lang="en"><meta charset="UTF-8"& ...

  8. 第五章 二叉树(e2)中序遍历

  9. Hamburgers

    Hamburgers http://codeforces.com/problemset/problem/371/C time limit per test 1 second memory limit ...

  10. 百度Cafe原理--Android自动化测试学习历程

    主要讲解内容及笔记: 一.Cafe原理 Cafe是一款自动化测试框架,解决问题:跨进程测试.快速深度测试 官网:http://baiduqa.github.io/Cafe/ Cafe provides ...