제출 #375630

#제출 시각아이디문제언어결과실행 시간메모리
375630KalashnikovMagenta (COCI21_magenta)C++17
0 / 110
179 ms16364 KiB
#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; }

컴파일 시 표준 에러 (stderr) 메시지

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) {
      |     ~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...