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>
using namespace std;
vector<int> who_wins(vector<int> own,
vector <int> imp, vector<int> from, vector<int> to) {
int n = own.size(), m = from.size();
vector<int> deg(n);
vector<vector<int>> adj(n);
for (int i = 0; i < m; i++) {
adj[to[i]].push_back(from[i]);
deg[from[i]]++;
}
while (true) {
vector<int> cnt(n), win(n);
queue<int> que;
for (int i = 0; i < n; i++)
if (imp[i]) {
que.push(i); win[i] = 1;
}
while (que.size()) {
int u = que.front(); que.pop();
for (int v : adj[u]) {
if (win[v]) continue;
if (own[v]) {
win[v] = 1; que.push(v);
} else if (++cnt[v] == deg[v]) {
win[v] = 1; que.push(v);
}
}
}
bool flag = false;
for (int i = 0; i < n; i++)
if (!win[i]) que.push(i);
while (que.size()) {
int u = que.front(); que.pop();
if (imp[u]) {
flag = true; imp[u] = 0;
}
for (int v : adj[u]) {
if (!win[v]) continue;
if (!own[v]) {
win[v] = 0; que.push(v);
} else if (++cnt[v] == deg[v]) {
win[v] = 0; que.push(v);
}
}
}
if (!flag) 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... |