The Suspects POJ - 1611

#include<iostream>
using namespace std;
const int N=30010;
int n,m,ans,p[N];
int find(int x)
{
    if(p[x]!=x)
        p[x]=find(p[x]);
    return p[x];
}
int main()
{
    while(cin>>n>>m,m||n)
    {
        int res=0;
        for(int i=0;i<=n;i++)
            p[i]=i;
        int num,fa;
        int temp;
        for(int i=0;i<m;i++)
        {
            cin>>num>>fa;
            fa=find(fa);
            num--;
            while(num--)
            {
                cin>>temp;
                p[find(temp)]=fa;
            }
        }
        int check=find(0);
        for(int i=0;i<=n;i++)
            if(find(i)==check)
                res++;
        cout<<res<<endl;
    }
}

原文地址:https://www.cnblogs.com/QingyuYYYYY/p/12248655.html

时间: 2024-10-09 05:55:43

The Suspects POJ - 1611的相关文章

kuangbin专题五:B - The Suspects POJ - 1611

B - The Suspects POJ - 1611 Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. To minimize transmission to others, the best strategy is to separate the suspects f

B - The Suspects POJ - 1611

B - The Suspects POJ - 1611 Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 61692   Accepted: 29146 Description Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mi

The Suspects POJ - 1611 并查集,同集合的数

Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. To minimize transmission to others, the best strategy is to separate the suspects from others.In the Not-Spread

POJ 1611 The Suspects(并查集)

The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 22296   Accepted: 10842 Description Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. T

POJ 1611 The Suspects(特别无语的并查集)

很简单的一道题目,开始用的是并查集的分离集合森林做,不知道怎么的特别不稳定,太奇怪了,WA无数次,无奈之下改成一维数组了..sad AC #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <math.h> #define PI acos(-1,0) using namespa

[ACM] POJ 1611 The Suspects (并查集,输出第i个人所在集合的总人数)

The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 21586   Accepted: 10456 Description Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. T

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

The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 21472   Accepted: 10393 Description Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. T

poj 1611(详解)

The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 22217   Accepted: 10805 Description Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. T

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

题目地址: http://poj.org/problem?id=1611 题目内容: The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 24253   Accepted: 11868 Description Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recogni