病毒扩散问题,SARS病毒最初感染了一个人就是0号可疑体,现在有N个学生,和M个团队,只要团队里面有一个是可疑体,那么整个团队都是可疑体,问最终有多少个人需要隔离...
再简单不过的并查集,只需要不断的合并每一行就行可,到最后查询一个所有与0相同的树根就行了
//////////////////////////////////////////////////////////////////
#include<stdio.h>

const int maxn  = 100005;

int f[maxn];
int Find(int x)
{
    if(f[x] != x)
        f[x] = Find(f[x]);
    return f[x];
} int main()
{
    int N, M;     while(scanf("%d%d", &N, &M), N+M)
    {
        int i, u, v, T;         for(i=0; i<N; i++)
            f[i] = i;         while(M--)
        {
            scanf("%d%d", &T, &u);
            u = Find(u);             while(--T)
            {
                scanf("%d", &v);
                v = Find(v);
                f[v] = u;
            }
        }         int ans = 1;
        u = Find(0);         for(i=1; i<N; i++)
        {
            if(Find(i) == u)
                ans++;
        }         printf("%d\n", ans);
    }     return 0;
}

B - The Suspects -poj 1611的更多相关文章

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

    链接: http://poj.org/problem?id=1611 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#probl ...

  2. The Suspects POJ 1611

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

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

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

  4. 【原创】poj ----- 1611 The Suspects 解题报告

    题目地址: http://poj.org/problem?id=1611 题目内容: The Suspects Time Limit: 1000MS   Memory Limit: 20000K To ...

  5. poj 1611 The Suspects 解题报告

    题目链接:http://poj.org/problem?id=1611 题意:给定n个人和m个群,接下来是m行,每行给出该群内的人数以及这些人所对应的编号.需要统计出跟编号0的人有直接或间接关系的人数 ...

  6. poj 1611 The Suspects(简单并查集)

    题目:http://poj.org/problem?id=1611 0号是病原,求多少人有可能感染 #include<stdio.h> #include<string.h> # ...

  7. POJ - 1611 The Suspects 【并查集】

    题目链接 http://poj.org/problem?id=1611 题意 给出 n, m 有n个人 编号为 0 - n - 1 有m组人 他们之间是有关系的 编号为 0 的人是 有嫌疑的 然后和 ...

  8. 【裸的并查集】POJ 1611 The Suspects

    http://poj.org/problem?id=1611 [Accepted] #include<iostream> #include<cstdio> #include&l ...

  9. 并查集 (poj 1611 The Suspects)

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

随机推荐

  1. Echarts使用随笔(2)-Echarts中mapType and data

    本文出处:http://blog.csdn.net/chenxiaodan_danny/article/details/39081071  series : [                {   ...

  2. 补充一下sql server(临时表)

    说明:(1).临时表其实是放在数据库tempdb里的一个用户表:(2).TempTableName必须带“#”,“#"可以是一个或者两个,以#(局部)或##(全局)开头的表,这种表在会话期间 ...

  3. Dictionary 总结

    foreach (KeyValuePair<int, string> kvp in myDictionary) {...} Dictionary<string, string> ...

  4. CouchBase 遇到问题笔记(一)

    刚开始看CouchBase,按照官网给出的示例,边敲边理解,遇到了一个很奇怪的问题,如下代码: IView<IViewRow> view = client.GetView("be ...

  5. 对UIImage进行的一些操作

    1.生成指定宽高的UIImage对象(oldImage为原始图片对象,newImage为操作后的图片对象) // 参数1:图片的尺寸 参数2:是否透明(没看出YES和NO有什么区别) 参数3:缩放(1 ...

  6. healthkit 记录每天用户的运动情况

    //详细操作步骤 http://www.csdn.net/article/2015-01-23/2823686-healthkit-tutorial-with-swift //官方api https: ...

  7. node http.request请求

    var http = require('http'); var querystring = require('querystring'); var path = '/cricket/getRecord ...

  8. java_设计模式_适配器模式_Adapter Pattern(2016-08-09)

    概念 将一个接口转换成客户希望的另外一个接口.(该模式使得原本不兼容的类可以一起工作). UML图 适配器模式有类的适配器模式和对象的适配器模式两种不同的形式. (1)对象的适配器模式结构图 (2)类 ...

  9. hdu 3308

    终于A了,我好想砍人,虽然这是一道基础的区间合并.但是这错误我也是醉了. 错误我表在注释里. 题目意思不多说,sha崽题目出的很简洁. #include <iostream>#includ ...

  10. C#遍历所有的Textbox控件并赋值为String.Empty

    foreach (Control control in this.Controls) { if (control.GetType().Name.Equals("TextBox")) ...