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 N = 5005;
int deg[N];
bool visit[N];
vector<int> G1[N], G2[N];
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
int n = a.size(), m = u.size();
for (int i = 0; i < m; ++i) {
G1[u[i]].push_back(v[i]), G2[v[i]].push_back(u[i]);
}
vector<int> res(n, 0);
while (1) {
for (int i = 0; i < n; ++i) visit[i] = 0;
queue<int> qu;
for (int i = 0; i < n; ++i) {
deg[i] = G1[i].size();
}
for (int i = 0; i < n; ++i) {
if (r[i]) qu.push(i);
}
while (qu.size()) {
int u = qu.front(); qu.pop();
for (auto v : G2[u]) {
if (a[v]) {
if (!visit[v]) {
visit[v] = 1;
if (!r[v]) qu.push(v);
}
}
else {
deg[v]--;
if (deg[v] == 0) {
visit[v] = 1;
if (!r[v]) qu.push(v);
}
}
}
}
bool flag = 0;
for (int i = 0; i < n; ++i) {
if (r[i] && !visit[i]) { r[i] = 0, flag = 1; }
}
if (flag) continue;
for (int i = 0; i < n; ++i) res[i] = visit[i];
break;
}
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... |