Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cstring>
- //#include <bits/stdc++.h>
- using namespace std;
- int n,m;
- const int INF = 1e9;
- vector<pair<int,int>>g[105];
- int memo[105][105][26][2];
- int dfs(int maks, int lukas, int turn, int last_char) {
- if(memo[maks][lukas][last_char][turn] != -1) {
- return memo[maks][lukas][last_char][turn];
- }
- int res;
- if(turn == 0) {
- res = -INF;
- for(pair<int, int> p: g[maks]) {
- if(last_char == -1) {
- res = max(res, dfs(p.first, lukas, 1 - turn, p.second));
- }
- else {
- if(p.second >= last_char) {
- res = max(res, dfs(p.first, lukas, 1 - turn, p.second));
- }
- }
- }
- }
- else {
- res = INF;
- for(pair<int, int> p: g[lukas]) {
- if(p.second >= last_char) {
- res = min(res, dfs(maks, p.first, 1 - turn, p.second));
- }
- }
- }
- memo[maks][lukas][last_char][turn] = res;
- return res;
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin>>n>>m;
- for(int i = 0;i<m;i++){
- int v,u;
- char ch;
- cin>>v>>u>>ch;
- g[v].push_back({u,ch-'a'});
- }
- memset(memo,-1,sizeof(memo));
- for(int i = 1;i<=n;i++){
- for(int j = 1;j<=n;j++){
- if(dfs(i, j, 0, -1) == INF) {
- cout << "A";
- }
- else {
- cout << "B";
- }
- }
- cout<<"\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment