#include <iostream>
using namespace std;
static int num[105];
static int numCount = 0;
static bool Nodeflag[105];
void numadd(int x){
if(Nodeflag[x] == false){
++numCount;
Nodeflag[x] = true;
}
}
int main(){
int a,b,count,testCount=0;
while(true){
count=0;
numCount = 0;
testCount++;
for(int i = 0; i < 105; ++i) Nodeflag[i] = false;
while(1){
scanf("%d",&a);
scanf("%d",&b);
if(a == 0 && b == 0 && count == 0) --count;
if(a == 0 && b == 0) break;
if(a == -1 && b == -1) return 0;
numadd(a);
numadd(b);
++count;
}
if(numCount == (count+1))
printf("Case %d is a tree.\n",testCount);
else
printf("Case %d is not a tree.\n",testCount);
}
}
POJ 1308 (边的个数 等于 结点的个数减一)
最新推荐文章于 2022-05-04 00:29:07 发布