| ||||||||||
| 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 | |||||||||
这样可以吗?有什么情况的输入是错误的呢?WA#include<stdio.h>
#include<stdlib.h>
#define INF 20
int Tree[INF+1][INF+1];
int In[INF+1],Out[INF+1];
int IsTree()
{
int i,flag,count;
flag=0;
for(i=1;i<=INF;i++)
{
if(In[i]>1) break;
if(In[i]==0&&Out[i]!=0&&flag) break;
if(In[i]==0&&Out[i]!=0) flag=1; //查根
}
if((i>INF)&&(flag==1)) return 1;
return 0;
}
main()
{
int a,b,i,j,count,flag,flag_kong;
count=1;
while(1)
{
flag=1;flag_kong=1;
for(i=0;i<=INF;i++)
{
In[i]=Out[i]=0;
for(j=0;j<=INF;j++) Tree[i][j]=0;
}
scanf("%d%d",&a,&b);
if(a==-1&&b==-1) break;
while(1)
{
if(a==0&&b==0) break;
flag_kong=0;
if(a==b||Tree[b][a]) flag=0;
if(Tree[a][b]==0)
{
Tree[a][b]=1;
In[b]++; Out[a]++;
}
scanf("%d%d",&a,&b);
}
if(flag_kong)
printf("Case %d is a tree.\n",count++);
else
{
if(flag==0)
printf("Case %d is not a tree.\n",count++);
else
if(IsTree())
printf("Case %d is a tree.\n",count++);
else
printf("Case %d is not a tree.\n",count++);
}
}
system("pause\n");
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator