| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 1045356 | MorePipisek | Magenta (COCI21_magenta) | C++14 | 81 ms | 8796 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
using namespace std;
int n, a, b;
vector<int> dist;
vector<vector<pair<int, int>>> g;
bool pih;
void dfs(int v, int d = 0, int p = -1) {
    if (v == b) {
        pih = d % 2 == 0;
        return;
    }
    for (auto [u, c] : g[v]) {
        if (u != p) {
            dfs(u, d + 1, v);
        }
    }
}
void visit(int v, int d = 0, int p = -1) {
    dist[v] = d;
    for (auto [u, c] : g[v]) {
        if (c != pih && u != p) {
            visit(u, d + 1, v);
        }
    }
}
bool safe = false;
void esc(int v, int d = 0, int p = -1) {
    for (auto [u, c] : g[v]) {
        if (u == p) {
            continue;
        }
        if (pih && dist[v] <= d) {
            continue;
        }
        if (!pih && dist[v] < d) {
            continue;
        }
        if (dist[v] == 1e9 && dist[u] == 1e9) {
            safe = true;
        }
        esc(u, d + 1, v);
    }
}
int main() {
    cin >> n >> a >> b;
    --a; --b;
    g.assign(n, {});
    for (int i = 0; i < n - 1; ++i) {
        int u, v, c; cin >> u >> v; --u; --v;
        string col; cin >> col;
        if (col == "plava") {
            c = 0;
        } else if (col == "crvena") {
            c = 1;
        } else {
            c = 2;
        }
        g[u].emplace_back(v, c);
        g[v].emplace_back(u, c);
    }
    bool lp = true, lm = true;
    for (auto [u, c] : g[a]) {
        lp &= c == 1;
    }
    for (auto [u, c] : g[b]) {
        lm &= c == 0;
    }
    if (lp) {
        cout << "Marin" << endl;
        return 0;
    } else if (lm) {
        cout << "Paula" << endl;
        return 0;
    }
    dfs(a);
    dist.assign(n, 1e9);
    if (pih) {
        visit(a);
        esc(b);
    } else {
        visit(b);
        esc(a);
    }
    if (safe) {
        cout << "Magenta" << endl;
    } else if (pih) {
        cout << "Paula" << endl;
    } else {
        cout << "Marin" << endl;
    }
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
