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 <bits/stdc++.h>
#include "train.h"
using namespace std;
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
int n = a.size(), m = u.size();
vector<vector<int>> adj(n);
vector<int> deg(n);
for (int i = 0; i < m; ++i) {
adj[v[i]].push_back(u[i]);
++deg[u[i]];
}
while (true) {
vector<int> win = r;
{
vector<int> degree = deg;
queue<int> q;
for (int i = 0; i < n; ++i) {
if (win[i]) {
q.push(i);
}
}
while (!q.empty()) {
int x = q.front();
q.pop();
for (auto y : adj[x]) {
if (!win[y]) {
if (a[y] || !--degree[y]) {
win[y] = 1;
q.push(y);
}
}
}
}
}
{
vector<int> degree = deg;
queue<int> q;
for (int i = 0; i < n; ++i) {
if (!win[i]) {
q.push(i);
}
}
while (!q.empty()) {
int x = q.front();
q.pop();
for (auto y : adj[x]) {
if (win[y]) {
if (!a[y] || !--degree[y]) {
win[y] = 0;
q.push(y);
}
}
}
}
}
bool changed = false;
for (int i = 0; i < n; ++i) {
if (r[i] && !win[i]) {
changed = true;
r[i] = 0;
}
}
if (!changed) {
return win;
}
}
}
# | 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... |