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"
using namespace std;
int n, m;
vector<int> edge[5000];
vector<int> redge[5000];
int outdegree[5000];
int stop[5000];
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
n = a.size();
m = u.size();
for (int i = 0; i < m; ++i) {
edge[u[i]].push_back(v[i]);
redge[v[i]].push_back(u[i]);
}
bool loop = true;
while (loop) {
vector<int> st;
for (int i = 0; i < n; ++i) {
stop[i] = r[i] ^ 1;
outdegree[i] = edge[i].size();
if (r[i]) st.push_back(i);
}
while (!st.empty()) {
int x = st.back();
st.pop_back();
for (int i : redge[x]) {
if (stop[i] == 0) continue;
--outdegree[i];
if (a[i] == 1 || outdegree[i] == 0) {
stop[i] = 0;
st.push_back(i);
}
}
}
for (int i = 0; i < n; ++i) {
if (stop[i] == 1) st.push_back(i);
outdegree[i] = edge[i].size();
}
while (!st.empty()) {
int x = st.back();
st.pop_back();
for (int i : redge[x]) {
if (stop[i] == 1) continue;
--outdegree[i];
if (a[i] == 0 || outdegree[i] == 0) {
stop[i] = 1;
st.push_back(i);
}
}
}
loop = false;
for (int i = 0; i < n; ++i) {
if (r[i] && stop[i]) loop = true, r[i] = 0;
}
}
vector<int> ret;
ret.resize(n);
for (int i = 0; i < n; ++i) {
ret[i] = stop[i] ^ 1;
}
return ret;
}
# | 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... |