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 |
哪位高手帮帮小弟看看,为什么老提示Wrong Answer,可是我试了很多的例子都没出错啊..#include<iostream> using namespace std; #define max 50050 int father[max]; int gengs[max]; int getfather(int temp) { if(father[temp]==temp) return temp; father[temp]=getfather(father[temp]); return father[temp]; } int main() { int n,i,j,stu1,stu2,num=0; long m; scanf("%d %d",&n,&m); while(n!=0||m!=0) { num++; for(i=1;i<=n;i++) father[i]=i; for(long l=0;l<m;l++) { scanf("%d %d",&stu1,&stu2); int x=getfather(stu1); int y=getfather(stu2); father[y]=x; } memset(gengs,0,sizeof(gengs[max])); for(i=1;i<=n;i++) gengs[getfather(i)]=1; int cust=0; for(j=1;j<=n;j++) cust+=gengs[j]; printf("Case %d: %d\n",num,cust); scanf("%d %d",&n,&m); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator