#include <bits/stdc++.h>
#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int N = 1e5+5;
vector<pair<int,int>> adj[N]; //u -> {v,0/1/2} => 0->blue, 1->red, 2-> magenta
int dis[N][2], can[N][2], cnt = 0, ok = 0, hunter;
bool blue,red;
int a,b, len;
void dfs(int u, int c, int par){
for(auto [v,cc] : adj[u]){
if(v==par) continue;
if(v==b) len = dis[u][c] + 1;
if(cc==(c^1)) continue;
dis[v][c] = dis[u][c]+1;
dfs(v,c,u);
}
}
void dfs2(int u, int par){
for(auto [v,cc] : adj[u]){
if(v==par||cc==hunter||(dis[v][hunter]!=-1&&dis[v][hunter] <= dis[u][hunter^1])) continue;
if(dis[u][hunter]==-1&&dis[v][hunter]==-1) ok = 1;
dfs2(v,u);
}
}
signed main(){
fastio
map<string,int> get;
get["plava"] = 0;
get["crvena"] = 1;
get["magenta"] = 2;
int n;
cin >> n;
cin >> a >> b;
bool onlyblue = 1;
for(int i = 1;i < n;i++){
int u,v; string s;
cin >> u >> v >> s;
if(s!="plava") onlyblue = 0;
adj[u].push_back({v,get[s]});
adj[v].push_back({u,get[s]});
if(get[s]!=1&&((u==a&&v!=b)||(u!=b&&v==a))) blue = 1;
if(get[s]!=0&&(u==b||v==b)) red = 1;
}
if(!blue){
cout << "Marin\n";
return 0;
}else if(!red){
cout << "Paula\n";
return 0;
}
fill(&dis[0][0],&dis[N-1][1],-1);
dis[a][0] = 0;
dfs(a,0,-1);
dis[b][1] = 0;
dfs(b,1,-1);
if(len&1^1) hunter = 0; else hunter = 1;
dfs2((!hunter ? b : a),-1);
if(!ok){
cout << (hunter==0 ? "Paula" : "Marin") << "\n";
}else{
cout << "Magenta\n";
}
}
Compilation message
Main.cpp: In function 'void dfs(long long int, long long int, long long int)':
Main.cpp:15:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
15 | for(auto [v,cc] : adj[u]){
| ^
Main.cpp: In function 'void dfs2(long long int, long long int)':
Main.cpp:25:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
25 | for(auto [v,cc] : adj[u]){
| ^
Main.cpp: In function 'int main()':
Main.cpp:63:8: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
63 | if(len&1^1) hunter = 0; else hunter = 1;
| ~~~^~
Main.cpp:41:7: warning: variable 'onlyblue' set but not used [-Wunused-but-set-variable]
41 | bool onlyblue = 1;
| ^~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2668 KB |
Output is correct |
2 |
Correct |
3 ms |
4224 KB |
Output is correct |
3 |
Correct |
3 ms |
4204 KB |
Output is correct |
4 |
Correct |
2 ms |
2668 KB |
Output is correct |
5 |
Correct |
3 ms |
4224 KB |
Output is correct |
6 |
Correct |
3 ms |
4204 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 |
2796 KB |
Output is correct |
10 |
Correct |
3 ms |
4204 KB |
Output is correct |
11 |
Correct |
3 ms |
4204 KB |
Output is correct |
12 |
Incorrect |
3 ms |
4204 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
98 ms |
9452 KB |
Output is correct |
2 |
Correct |
99 ms |
9480 KB |
Output is correct |
3 |
Correct |
103 ms |
9452 KB |
Output is correct |
4 |
Correct |
89 ms |
9452 KB |
Output is correct |
5 |
Correct |
89 ms |
9452 KB |
Output is correct |
6 |
Correct |
2 ms |
2668 KB |
Output is correct |
7 |
Correct |
3 ms |
4224 KB |
Output is correct |
8 |
Correct |
3 ms |
4204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2668 KB |
Output is correct |
2 |
Correct |
3 ms |
4224 KB |
Output is correct |
3 |
Correct |
3 ms |
4204 KB |
Output is correct |
4 |
Correct |
2 ms |
2668 KB |
Output is correct |
5 |
Correct |
3 ms |
4224 KB |
Output is correct |
6 |
Correct |
3 ms |
4204 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 |
2796 KB |
Output is correct |
10 |
Correct |
3 ms |
4204 KB |
Output is correct |
11 |
Correct |
3 ms |
4204 KB |
Output is correct |
12 |
Incorrect |
3 ms |
4204 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |