| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
求助巨佬 为什么会WART。
code:
#include<cstdio>
int father[30010],n,m,s,x,y;
int getroot(int x) {
father[x]=father[father[x]];
if(father[x]==x) return x;
return getroot(father[x]);
}
int main() {
//freopen("suspect.in","r",stdin);
//freopen("suspect.out","w",stdout);
while(scanf("%d%d",&n,&m)!=EOF and n||m) {
for(int i=0;i<n;i++) father[i]=i;
for(int i=0;i<m;i++) {
scanf("%d%d",&s,&x);
int x1=getroot(x);
for(int j=1;j<s;j++) {
scanf("%d",&y);
int y1=getroot(y);
if(x1!=y1) father[x1]=y1;
}
}
int x0=getroot(0),p=0;
for(int i=0;i<n;i++)
if(getroot(i)==x0) p++;
printf("%d\n",p);
}
//fclose(stdin);
//fclose(stdout);
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator