#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<long long, long long>
#define plll pair<long long, pll>
#define ff first
#define ss second
#define ee ss.ff
#define rr ss.ss
//#define DEBUG
using namespace std;
vector<pii> gph[101010];
pii par[101010];
int dst(int x, int p, int y, int d)
{
if(x == y) return d;
for(auto [i, j] : gph[x]) if(i != p)
{
int t = dst(i, x, y, d + 1);
if(t != -1) return t;
}
return -1;
}
void dfs(int x, int p)
{
vector<pii> tmp;
for(auto [y, i] : gph[x]) if(y != p)
{
tmp.push_back({y, i});
par[y] = {x, i};
dfs(y, x);
}
gph[x] = tmp;
}
bool sol(int x, int s)
{
if(s == 1)
{
for(auto [y, i] : gph[x]) if(i) return true;
return false;
}
for(auto [y, i] : gph[x])
{
if(i == 1) if(sol(y, 1)) return true;
if(i == 2) if(sol(y, 0)) return true;
}
return false;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n; cin >> n;
int a, b; cin >> a >> b; --a; --b;
for(int i = 1; i < n; ++i)
{
int x, y; cin >> x >> y; --x; --y;
int c;
#ifdef DEBUG
cin >> c;
#else //DEBUG
string st; cin >> st;
if(st == "plava") c = 0;
else if(st == "crvena") c = 1;
else c = 2;
#endif //DEBUG
gph[x].push_back({y, c});
gph[y].push_back({x, c});
}
bool flag = false; for(auto i : gph[a]) if(i.ss != 1 && i.ff != b) flag = true; if(!flag) { cout << "Marin"; return 0; }
flag = false; for(auto i : gph[b]) if(i.ss != 0) flag = true; if(!flag) { cout << "Paula"; return 0; }
int d = dst(a, -1, b, 0);
int x = a, y = b;
if(d & 1)
{
swap(x, y);
for(int i = 0; i < n; ++i)
for(auto &j : gph[i])
if(j.ss < 2) j.ss = 1 - j.ss;
}
dfs(x, -1);
int root = y;
for(int i = 0; i < (d - 1) / 2; ++i)
{
if(!par[root].ss) break;
root = par[root].ff;
}
for(int i = par[root].ff; i != x; i = par[i].ff) if(par[i].ss == 1) { cout << "Magenta"; return 0; }
if(sol(root, par[root].ss == 1)) cout << "Magenta";
else if(d & 1) cout << "Marin";
else cout << "Paula";
}
Compilation message
Main.cpp: In function 'int dst(int, int, int, int)':
Main.cpp:23:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
23 | for(auto [i, j] : gph[x]) if(i != p)
| ^
Main.cpp: In function 'void dfs(int, int)':
Main.cpp:34:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
34 | for(auto [y, i] : gph[x]) if(y != p)
| ^
Main.cpp: In function 'bool sol(int, int)':
Main.cpp:47:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
47 | for(auto [y, i] : gph[x]) if(i) return true;
| ^
Main.cpp:51:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
51 | for(auto [y, i] : gph[x])
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2668 KB |
Output is correct |
2 |
Correct |
2 ms |
2668 KB |
Output is correct |
3 |
Correct |
2 ms |
2668 KB |
Output is correct |
4 |
Correct |
2 ms |
2688 KB |
Output is correct |
5 |
Correct |
2 ms |
2668 KB |
Output is correct |
6 |
Correct |
3 ms |
2668 KB |
Output is correct |
7 |
Correct |
2 ms |
2668 KB |
Output is correct |
8 |
Correct |
2 ms |
2668 KB |
Output is correct |
9 |
Correct |
2 ms |
2668 KB |
Output is correct |
10 |
Correct |
2 ms |
2668 KB |
Output is correct |
11 |
Correct |
2 ms |
2668 KB |
Output is correct |
12 |
Correct |
2 ms |
2668 KB |
Output is correct |
13 |
Correct |
2 ms |
2668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
91 ms |
7276 KB |
Output is correct |
2 |
Correct |
83 ms |
7404 KB |
Output is correct |
3 |
Correct |
89 ms |
7276 KB |
Output is correct |
4 |
Correct |
82 ms |
7276 KB |
Output is correct |
5 |
Correct |
74 ms |
7448 KB |
Output is correct |
6 |
Correct |
3 ms |
2668 KB |
Output is correct |
7 |
Correct |
2 ms |
2668 KB |
Output is correct |
8 |
Correct |
2 ms |
2668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2668 KB |
Output is correct |
2 |
Correct |
2 ms |
2668 KB |
Output is correct |
3 |
Correct |
2 ms |
2668 KB |
Output is correct |
4 |
Correct |
2 ms |
2688 KB |
Output is correct |
5 |
Correct |
2 ms |
2668 KB |
Output is correct |
6 |
Correct |
3 ms |
2668 KB |
Output is correct |
7 |
Correct |
2 ms |
2668 KB |
Output is correct |
8 |
Correct |
2 ms |
2668 KB |
Output is correct |
9 |
Correct |
2 ms |
2668 KB |
Output is correct |
10 |
Correct |
2 ms |
2668 KB |
Output is correct |
11 |
Correct |
2 ms |
2668 KB |
Output is correct |
12 |
Correct |
2 ms |
2668 KB |
Output is correct |
13 |
Correct |
2 ms |
2668 KB |
Output is correct |
14 |
Correct |
91 ms |
7276 KB |
Output is correct |
15 |
Correct |
83 ms |
7404 KB |
Output is correct |
16 |
Correct |
89 ms |
7276 KB |
Output is correct |
17 |
Correct |
82 ms |
7276 KB |
Output is correct |
18 |
Correct |
74 ms |
7448 KB |
Output is correct |
19 |
Correct |
3 ms |
2668 KB |
Output is correct |
20 |
Correct |
2 ms |
2668 KB |
Output is correct |
21 |
Correct |
2 ms |
2668 KB |
Output is correct |
22 |
Correct |
2 ms |
2668 KB |
Output is correct |
23 |
Correct |
2 ms |
2668 KB |
Output is correct |
24 |
Correct |
2 ms |
2668 KB |
Output is correct |
25 |
Correct |
2 ms |
2668 KB |
Output is correct |
26 |
Correct |
2 ms |
2668 KB |
Output is correct |
27 |
Correct |
2 ms |
2796 KB |
Output is correct |
28 |
Correct |
2 ms |
2668 KB |
Output is correct |
29 |
Correct |
2 ms |
2668 KB |
Output is correct |
30 |
Correct |
2 ms |
2668 KB |
Output is correct |
31 |
Correct |
53 ms |
6508 KB |
Output is correct |
32 |
Correct |
50 ms |
6508 KB |
Output is correct |
33 |
Correct |
112 ms |
7276 KB |
Output is correct |
34 |
Correct |
86 ms |
7404 KB |
Output is correct |