# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1045356 | MorePipisek | Magenta (COCI21_magenta) | C++14 | 81 ms | 8796 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
}
컴파일 시 표준 에러 (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... |