Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <bits/stdc++.h>
- using namespace std;
- int n, m;
- vector<pair<int, char>> graph[105];
- int dp[105][105][30][2];
- // +INF -- max win
- // -INF -- lucas win
- int rec(int max_node, int lucas_node, int last_char, int turn) {
- if(dp[max_node][lucas_node][last_char][turn] != -1) {
- return dp[max_node][lucas_node][last_char][turn];
- }
- int result;
- if(turn == 0) {
- result = -(2e9);
- for(int i = 0; i < graph[max_node].size(); i++) {
- int neighbour = graph[max_node][i].first;
- int val = (int) graph[max_node][i].second;
- if(last_char <= val) {
- result = max(result, rec(neighbour, lucas_node, val, 1));
- }
- }
- }
- else {
- result = (2e9);
- for(int i = 0; i < graph[lucas_node].size(); i++) {
- int neighbour = graph[lucas_node][i].first;
- int val = (int) graph[lucas_node][i].second;
- if(last_char <= val) {
- result = min(result, rec(max_node, neighbour, val, 0));
- }
- }
- }
- return dp[max_node][lucas_node][last_char][turn] = result;
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin >> n >> m;
- for(int i = 0; i < m; i++) {
- int a, b;
- char c;
- cin >> a >> b >> c;
- a--; b--;
- graph[a].push_back(make_pair(b, (c - 'a') + 1));
- }
- memset(dp, -1, sizeof dp);
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < n; j++) {
- if(rec(i, j, 0, 0) == 2e9) {
- cout << "A";
- }
- else {
- cout << "B";
- }
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement