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:大牛求指点,数据都过了,wa的好辛苦In Reply To:大牛求指点,数据都过了,wa的好辛苦 Posted by:1004101213 at 2011-10-31 00:15:30 > #include<iostream> > #include<cstdio> > #include<cstring> > #include<string> > #include<algorithm> > using namespace std; > int f[1005]; > int main() > { > int a,b,ca(1),k,i; > while(scanf("%d%d",&a,&b),a!=-1||b!=-1) > { > int flag=0; > memset(f,-1,sizeof(f)); > if(a==0&&b==0) { printf("Case %d is a tree.\n",ca++);continue;} > //空树 > if(a==b) flag=1;//指向自己 > f[b]=f[a]=a; > int c,d,k=2; > while(scanf("%d%d",&c,&d),c||d) > { > if(f[c]==-1)k++; > if(f[d]==-1)k++; > if(c==d||f[d]!=d&&f[d]!=-1||f[c]==c&&f[d]==c)flag=1; > //判重,成环 > f[d]=f[c]=c; > } > if(flag){printf("Case %d is not a tree.\n",ca++);continue;} > int ans=0; > for(i=0;i<k;i++) > if(f[i]==i)ans++;//森林 > if(ans==1)printf("Case %d is a tree.\n",ca++); > else printf("Case %d is not a tree.\n",ca++); > } > > > return 0; > } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator