| ||||||||||
| 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:Re:大牛求指点,数据都过了,wa的好辛苦 Posted by:1004101213 at 2011-10-31 12:55:22 #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
int f[1005],tree[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,0,sizeof(f));
memset(tree,0,sizeof(tree));
if(a==0&&b==0) { printf("Case %d is a tree.\n",ca++);continue;}
if(a==b) flag=1;
f[b]=a;
tree[a]=1,tree[b]=1;
int c,d;
while(scanf("%d%d",&c,&d),c||d)
{
if(f[d]!=0)flag=1;
f[d]=c;
tree[c]=1,tree[d]=1;
}
if(flag){printf("Case %d is not a tree.\n",ca++);continue;}
int ans=0;
for(i=0;i<1005;i++)
if(f[i]==0&&tree[i]==1)ans++;
if(ans==1)printf("Case %d is a tree.\n",ca++);
else printf("Case %d is not a tree.\n",ca++);
}
return 0;
}
这种方法好多了,一开始想多了,不知道卡在哪里了,总之A了。。。
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator