fork download
  1. #include <bits/stdc++.h>
  2. #define all(x) x.begin(),x.end()
  3. #define sz(x) (ll)x.size()
  4. #define foor(x,s,y) for(ll x = s ; x < y ; x++)
  5. #define ff first
  6. #define ss second
  7. #define mod 1000000007LL
  8. #define mmst(ar,va) memset(ar , va , sizeof(ar))
  9. #define ndl "\n"
  10.  
  11. typedef long long ll;
  12. typedef long double ld;
  13. using namespace std;
  14.  
  15. //const ld PI = acos(-1);
  16.  
  17. char ccc;
  18. ll n, m, ma, lu, l, r;
  19. ll mem[101][101][2][30];
  20. ll adj[101][101] , ret;
  21.  
  22. ll dfs(ll pm , ll pl ,bool turn , ll ch){
  23. ll &ret = mem[pm][pl][turn][ch];
  24.  
  25. if(~ret)
  26. return ret;
  27.  
  28. ret = !turn;
  29.  
  30. if(turn){
  31. foor(i,1,n+1){
  32. if(adj[pm][i] >= ch){
  33. ret = max(ret , dfs(i , pl , !turn , adj[pm][i]));
  34. }
  35. }
  36. }
  37.  
  38. else{
  39. foor(i,1,n+1){
  40. if(adj[pl][i] >= ch){
  41. ret = min(ret , dfs(pm , i , !turn , adj[pl][i]));
  42. }
  43. }
  44. }
  45.  
  46. return ret;
  47. }
  48.  
  49. int main()
  50. {
  51. ios::sync_with_stdio(false);cin.tie(NULL);
  52. //freopen("input.txt", "r", stdin);
  53. //freopen("output.txt", "w", stdout);
  54.  
  55. cin>>n>>m;
  56. mmst(adj , -1);
  57. foor(i,0,m){
  58. cin>>l>>r>>ccc;
  59. adj[l][r] = (ccc - 'a');
  60. }
  61.  
  62. mmst(mem , -1);
  63.  
  64. foor(i,1,n+1){
  65. foor(j,1,n+1){
  66. cout<<(dfs(i,j,1,0) ? 'A' : 'B');
  67. }
  68. cout<<ndl;
  69. }
  70.  
  71. return 0;
  72. }
  73.  
Success #stdin #stdout 0s 20928KB
stdin
4 4
1 2 b
1 3 a
2 4 c
3 4 b
stdout
BAAA
ABAA
BBBA
BBBB