首页 > 其他 > 详细

The Suspects POJ - 1611

时间:2020-02-01 15:57:15      阅读:50      评论:0      收藏:0      [点我收藏+]
#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;
    }
}

 

The Suspects POJ - 1611

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!