# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1045356 | 2024-08-05T21:06:40 Z | MorePipisek | Magenta (COCI21_magenta) | C++14 | 81 ms | 8796 KB |
#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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 344 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Incorrect | 1 ms | 344 KB | Output isn't correct |
8 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 59 ms | 8796 KB | Output is correct |
2 | Correct | 62 ms | 8788 KB | Output is correct |
3 | Correct | 57 ms | 8784 KB | Output is correct |
4 | Correct | 81 ms | 8748 KB | Output is correct |
5 | Correct | 56 ms | 8596 KB | Output is correct |
6 | Correct | 0 ms | 344 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 344 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Incorrect | 1 ms | 344 KB | Output isn't correct |
8 | Halted | 0 ms | 0 KB | - |