forked from marioyc/Online-Judge-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1589 - Professor Jhon.cpp
executable file
·67 lines (51 loc) · 1.69 KB
/
1589 - Professor Jhon.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
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
int N,m;
char c[100][3];
bool valid[26];
bool M1[100][100],M2[100][100],found;
scanf("%d\n",&N);
for(int tc=1;tc<=N;tc++){
scanf("%d\n",&m);
for(int i=0;i<m;i++) scanf("%c%c%c\n",&c[i][0],&c[i][1],&c[i][2]);
fill(valid,valid+26,false);
for(int i=0;i<26;i++) fill(M1[i],M1[i]+26,false);
for(int i=0;i<m;i++){
valid[c[i][0]-'A']=true;
valid[c[i][2]-'A']=true;
if(c[i][1]=='<') M1[c[i][0]-'A'][c[i][2]-'A']=true;
else M1[c[i][2]-'A'][c[i][0]-'A']=true;
}
for(int i=0;i<26;i++)
for(int j=0;j<26;j++)
M2[i][j]=M1[i][j];
for(int k=0;k<26;k++){
if(!valid[k]) continue;
for(int i=0;i<26;i++){
if(!valid[i]) continue;
for(int j=0;j<26;j++){
if(!valid[j]) continue;
M2[i][j]|=M2[i][k]&M2[k][j];
}
}
}
printf("Case %d:\n",tc);
found=false;
for(int i=0;i<26;i++){
if(!valid[i]) continue;
for(int j=0;j<26;j++){
if(!valid[j]) continue;
if(M2[i][j] && !M1[i][j]){
printf("%c<%c\n",i+'A',j+'A');
found=true;
}
}
}
if(!found) printf("NONE\n");
}
return 0;
}