#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define all(a) a.begin() , a.end()
#define F first
#define S second
using namespace std;
using ll = long long;
const int N = 2e5+5 , inf = 2e9 + 7;
const ll INF = 1e18 , mod = 1e9+7 , P = 6547;
int u[N] , jeski[N][2] , d[N];
vector<pair<int,string>> g[N];
void solve() {
int n , dist;
cin >> n;
int a , b;
cin >> a >> b;
for(int i = 1; i < n; i ++) {
int a , b;
cin >> a >> b;
string s;
cin >> s;
g[a].push_back({b , s});
g[b].push_back({a , s});
}
const string rail[2] = {"plava" , "crvena"};
queue<int> q[2];
q[0].push(a);
q[1].push(b);
int canDraw[2];
u[a] = 1;
u[b] = 2;
while(q[0].size() + q[1].size()) {
for(int t = 0; t < 2; t ++) {
if(q[t].empty()) continue;
int cur = q[t].front();
q[t].pop();
for(auto to: g[cur]) {
if(u[to.F] == 0 && (to.S == rail[t] || to.S == "magenta") ) {
if(jeski[cur][t]) {
canDraw[t] = 1;
}
if(to.S == rail[t]) {
jeski[to.F][t] = 1;
}
u[to.F] = t+1;
d[to.F] = d[cur]+1;
q[t].push(to.F);
}
if(u[to.F] != t+1 && u[to.F] != 0) {
//cout << to.F << ' ' << cur << '\n';
dist = d[to.F] + d[cur] + 1;
}
}
}
}
// cout << dist << '\n';
if(dist % 2 == 1) {
if(canDraw[0])
cout << "Magenta";
else
cout << "Marin\n";
}
else {
if(canDraw[1])
cout << "Magenta";
else
cout << "Paula";
}
}
/*
*/
main() {
//ios;
int tt = 1;
//cin >> tt;
while(tt --) {
solve();
}
return 0;
}
Compilation message
Main.cpp:79:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
79 | main() {
| ^
Main.cpp: In function 'void solve()':
Main.cpp:64:10: warning: 'dist' may be used uninitialized in this function [-Wmaybe-uninitialized]
64 | if(dist % 2 == 1) {
| ~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
4972 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
162 ms |
16236 KB |
Output is correct |
2 |
Correct |
160 ms |
16364 KB |
Output is correct |
3 |
Correct |
179 ms |
16236 KB |
Output is correct |
4 |
Incorrect |
153 ms |
16236 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
4972 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |