标签:severe acute respira an atypical pneumoni was recognized
The Suspects<span style="color:#3333ff;">/*
***************************************************
author : Grant Yuan
time : 2014.7.24
algorithm: 并查集
***************************************************
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#define MAX 30001
using namespace std;
int par[MAX];
int high[MAX];
int n,m,k,t0,t;
void init()
{
for(int i=0;i<n;i++)
{
par[i]=i;
high[i]=0;
}
}
int find(int x)
{
if(par[x]==x) return x;
else
return par[x]=find(par[x]);
}
void unite(int x,int y)
{
x=find(x);
y=find(y);
if(x==y) return;
if(high[x]<high[y]){
par[x]=y;
}
else{
par[y]=x;
if(high[x]==high[y]) high[x]++;
}
}
bool same(int x,int y)
{
return find(x)==find(y);
}
int main()
{ int f1,f2,ans;;
while(~scanf("%d%d",&n,&m)&&m+n){
ans=0;
init();
if(m==0)
cout<<"1"<<endl;
else{
for(int i=0;i<m;i++)
{
scanf("%d%d",&k,&t0);
for(int i=1;i<k;i++)
{
scanf("%d",&t);
f1=find(t0);
f2=find(t);
unite(f1,f2);
}
}
for(int i=0;i<n;i++)
{
if(find(0)==find(i))
ans++;
}
cout<<ans<<endl;}
}
return 0;
}
</span>标签:severe acute respira an atypical pneumoni was recognized
原文地址:http://blog.csdn.net/yuanchang_best/article/details/38074115