-
Notifications
You must be signed in to change notification settings - Fork 1
/
D.cpp
60 lines (51 loc) · 1.19 KB
/
D.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
#include <bits/stdc++.h>
using namespace std;
vector <int> graph[109], cost[109];
int dp[109][109][30][2];
int solve(int i, int j, int cst, int round)
{
int &ret = dp[i][j][cst][round];
if(ret != -1)
return ret;
ret = 0;
if(round == 0) {
for(int k = 0; k < graph[i].size(); k++) {
if(cost[i][k] >= cst) {
if(!solve(graph[i][k], j, cost[i][k], round^1) )
ret = 1;
}
}
}
else {
for(int k = 0; k < graph[j].size(); k++) {
if(cost[j][k] >= cst) {
if(!solve(i, graph[j][k], cost[j][k], round^1) )
ret = 1;
}
}
}
return ret;
}
int main()
{
int n, m;
cin >> n >> m;
for(int i = 1; i <= m; i++) {
int u, v;
char ch;
scanf("%d %d %c", &u, &v, &ch);
graph[u].push_back(v);
cost[u].push_back(ch - 'a');
}
memset(dp, -1, sizeof(dp));
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
if( solve(i, j, 0, 0) )
printf("A");
else
printf("B");
}
printf("\n");
}
return 0;
}