Submission #768064

#TimeUsernameProblemLanguageResultExecution timeMemory
768064SanguineChameleonToy Train (IOI17_train)C++17
0 / 100
305 ms1348 KiB
#include "train.h" #include <bits/stdc++.h> using namespace std; const int maxn = 5e3 + 20; int deg[maxn]; vector<int> adj[maxn]; int cnt[maxn]; int owner[maxn]; bool rem[maxn]; bool flag[maxn][2]; int n, m; void bfs(int player) { deque<int> q; for (int i = 0; i < n; i++) { if (flag[i][player]) { q.push_back(i); } cnt[i] = 0; } while (!q.empty()) { int u = q.front(); q.pop_front(); for (auto v: adj[u]) { cnt[v]++; if (owner[v] == player) { if (cnt[v] == 1) { flag[v][player] = true; q.push_back(v); } } else { if (cnt[v] == deg[v]) { flag[v][player] = true; q.push_back(v); } } } } } vector<int> who_wins(vector<int> _owner, vector<int> charge, vector<int> u, vector<int> v) { n = _owner.size(); for (int i = 0; i < n; i++) { owner[i] = _owner[i]; } m = u.size(); vector<int> res(n); while (true) { for (int i = 0; i < n; i++) { deg[i] = 0; adj[i].clear(); flag[i][0] = false; flag[i][1] = false; } for (int i = 0; i < m; i++) { if (!rem[u[i]] && !rem[v[i]]) { deg[u[i]]++; adj[v[i]].push_back(u[i]); } } for (int i = 0; i < n; i++) { if (!rem[i] && charge[i]) { flag[i][1] = true; } } bfs(1); bool done = true; for (int i = 0; i < n; i++) { if (!rem[i] && !flag[i][1]) { flag[i][0] = true; done = false; } } if (done) { for (int i = 0; i < n; i++) { if (!rem[i]) { res[i] = 1; } } break; } bfs(0); for (int i = 0; i < n; i++) { if (!rem[i] && flag[i][0]) { res[i] = 0; rem[i] = true; } } } return res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...