-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathPARADOX.cpp
84 lines (75 loc) · 1.24 KB
/
PARADOX.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
/*
AUTHOR: Akhilesh Anandh
Solution for "Paradox" (www.spoj.com/problems/PARADOX)
Algorithm: DFS
*/
#include<cstdio>
#include<cstring>
struct st{
int s_no;
bool val;
};
typedef struct st Statement;
bool contra = false;
Statement sts[101];
int vals[101];
int fr[101];
int from;
void traverse(int sn){
fr[sn] = from;
Statement s = sts[sn];
if((vals[sn]==1&&s.val)||(vals[sn]==0&&!s.val)){
if(vals[s.s_no]==0){
contra = true;
return;
}
else if(vals[s.s_no]==-1){
vals[s.s_no] = 1;
traverse(s.s_no);
}
}
else{
if(vals[s.s_no]==1){
contra = true;
return;
}
else if(vals[s.s_no]==-1){
vals[s.s_no]=0;
traverse(s.s_no);
}
}
}
int main(){
int n,j,i;
char str[10];
while(1){
scanf("%d",&n);
if(!n) break;
for(i=1;i<=n;i++){
scanf("%d",&(sts[i].s_no));
scanf("%s",str);
if(strcmp(str,"false")){
sts[i].val = true;
}
else sts[i].val = false;
vals[i] = -1;
}
for(j=1;j<=100;j++){
if(vals[j]!=-1) continue;
contra = false;
vals[j] = 1;
from = j;
traverse(j);
if(contra){
for(i=1;i<=n;i++) if(fr[i]==j) vals[i] = -1;
vals[j] = 0;
contra = false;
traverse(j);
}
if(contra) break;
}
if(!contra) printf("NOT ");
printf("PARADOX\n");
}
return 0;
}