标签:out nts 多少 win his tor input mem mini
| Time Limit: 1000MS | Memory Limit: 20000K | |
| Total Submissions: 35206 | Accepted: 17097 |
Description
Input
Output
Sample Input
100 4 2 1 2 5 10 13 11 12 14 2 0 1 2 99 2 200 2 1 5 5 1 2 3 4 5 1 0 0 0
Sample Output
4 1 1
Source
#include<stdio.h>
#include<string.h>
int father[30050],n;
void init()
{
int i;
memset(father,-1,sizeof(father));
for(i=0;i<n;++i) father[i]=i;
}
int find(int x)
{
if(x==father[x]) return (x);
else father[x]=find(father[x]);
return (father[x]);
}
void merge(int x,int y)
{
if(find(x)!=find(y)) father[find(x)]=find(y);
}
int main()
{
int m,i,qnum,x,pre,ans;
while(~scanf("%d%d",&n,&m))
{
if(n==0&&m==0) break;
init();
while(m--)
{
scanf("%d",&qnum);
scanf("%d",&pre);
for(i=1;i<qnum;++i)
{
scanf("%d",&x);
merge(x,pre);
}
}
ans=0;
for(i=0;i<n;++i) if(find(i)==find(0)) ++ans;
printf("%d\n",ans);
}
return 0;
}
标签:out nts 多少 win his tor input mem mini
原文地址:http://www.cnblogs.com/fuermowei-sw/p/6187788.html