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 |
哪位能给看看阿?怎么老RE呢?!#include<stdio.h> int father[30001],i,j; void init(int n) { for(i=0;i<n;i++)father[i]=i; } int find(int p) { if(father[p]!=p) father[p]=find(father[p]); return father[p]; } int main() { int n,m; while(1) { scanf("%d",&n); if(!n) break; scanf("%d",&m); init(n); int k,tmp1,tmp2; for(i=0;i<m;i++) { scanf("%d",&k); scanf("%d",&tmp1); for(j=1;j<k;j++) { scanf("%d",&tmp2); father[find(tmp2)]=tmp1; } } father[find(0)]=0; father[0]=0; int ans=1; for(i=1;i<n;i++) if(find(i)==0) ans++; printf("%d\n",ans); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator