forked from mohitsh/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparadox.cpp
39 lines (39 loc) · 1.07 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
// 2016-04-28
#include <cstdio>
#include <vector>
using namespace std;
int main() {
int N;
for (;;) {
scanf("%d", &N);
if (!N) return 0;
vector<vector<char>> adj(2*N, vector<char>(2*N));
for (int i = 0; i < N; i++) {
int j; char s[10];
scanf("%d %s", &j, s); j--;
if (s[0] == 't') {
adj[i][j] = true; adj[j+N][i+N] = true;
adj[i+N][j+N] = true; adj[j][i] = true;
} else {
adj[i][j+N] = true; adj[j][i+N] = true;
adj[i+N][j] = true; adj[j+N][i] = true;
}
}
for (int k = 0; k < 2*N; k++) {
for (int i = 0; i < 2*N; i++) {
for (int j = 0; j < 2*N; j++) {
adj[i][j] |= adj[i][k] && adj[k][j];
}
}
}
bool paradox = false;
for (int i = 0; i < N; i++) {
paradox |= adj[i][i+N];
}
if (paradox) {
puts("PARADOX");
} else {
puts("NOT PARADOX");
}
}
}