This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
void bfs(int player) {
deque<int> q;
for (int i = 0; i < n; i++) {
if (!rem[i] && 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]) {
if (flag[v][player]) {
continue;
}
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];
}
int 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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |