应该是目前最少的代码了。(喜欢偷懒嘿嘿嘿)
#include <stdio.h> int main() { int a, b;int Case=0; while(1) { Case++; int rudu[10001]={0};int point[10001]={0};int num=0;int root=0; while (scanf("%d %d", &a, &b) != EOF) { if (a == 0 && b == 0) break; if (a == -1 && b == -1)return 0; rudu[b]++;num++;point[a]++;point[b]++; } if(num==0){ printf("Case %d is a tree.\n",Case); continue; } for(int i=1;i<=10000;i++){ if(point[i]!=0&&rudu[i]==0)root++; else if(point[i]!=0&&rudu[i]>1){ printf("Case %d is not a tree.\n",Case); root=100; break; } } if(root==1)printf("Case %d is a tree.\n",Case); else if(root==100) continue; else printf("Case %d is not a tree.\n",Case); } return 0; }