forked from zhuli19901106/poj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
POJ1308(AC).cpp
86 lines (79 loc) · 1.45 KB
/
POJ1308(AC).cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
int main()
{
int involved[10001];
int ind[10001];
int outd[10001];
int in;
int out;
int caseno;
int sum;
int count1;
int i;
bool cycle;
int nodecount;
caseno = 1;
while(true){
memset(involved, 0, 10001 * sizeof(int));
memset(ind, 0, 10001 * sizeof(int));
memset(outd, 0, 10001 * sizeof(int));
scanf("%d%d", &in, &out);
if(in == -1 && out == -1){
break;
}else{
cycle = false;
if(in == 0 && out == 0){
printf("Case %d is a tree.\n", caseno);
caseno++;
continue;
}else if(in == out){
cycle = true;
}
outd[in]++;
ind[out]++;
involved[in] = involved[out] = 1;
while(true){
scanf("%d%d", &in, &out);
if(in == 0 && out == 0){
break;
}else{
if(in == out){
cycle = true;
}outd[in]++;
ind[out]++;
involved[in] = involved[out] = 1;
}
}
sum = 0;
count1 = 0;
nodecount = 0;
for(i = 1; i < 10001; i++){
sum += ind[i];
if(ind[i] == 1){
count1++;
}
if(involved[i] == 1){
nodecount++;
}
}
if(cycle == true){
printf("Case %d is not a tree.\n", caseno);
caseno++;
continue;
}else if(sum == count1 && count1 == nodecount - 1){
printf("Case %d is a tree.\n", caseno);
caseno++;
continue;
}else{
printf("Case %d is not a tree.\n", caseno);
caseno++;
continue;
}
}
}
return 0;
}