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;
using pii = pair<int, int>;
const int N = 5e3+10;
vector<int> G[N], R[N];
int need[N];
bool win[N];
void dfs(int u, int r=0) {
need[u] = 0;
if (!r) win[u] = true;
for (auto v : R[u]) if (--need[v] == 0)
dfs(v, r);
}
vector<int> who_wins(vector<int> A, vector<int> C, vector<int> U, vector<int> V)
{
int n = A.size();
int m = U.size();
for (int i = 0; i < m; ++i) {
G[U[i]].push_back(V[i]);
R[V[i]].push_back(U[i]);
}
while (true) {
// find all nodes that A can force to charger
for (int u = 0; u < n; ++u)
win[u] = false, need[u] = A[u] ? 1 : (int)G[u].size();
for (int u = 0; u < n; ++u) if (C[u] && need[u] > 0)
dfs(u);
// for nodes that A can't force, find which nodes B could force movement from
for (int u = 0; u < n; ++u)
need[u] = A[u] ? (int)G[u].size() : 1;
for (int u = 0; u < n; ++u) if (!win[u] && need[u] > 0)
dfs(u, 1);
// if B could win on some charger, remove charger
bool mod = false;
for (int u = 0; u < n; ++u) if (need[u] <= 0 && C[u])
C[u] = false, mod = true;
if (!mod) break;
}
vector<int> ans(n);
for (int u = 0; u < n; ++u) if (need[u] > 0)
ans[u] = 1;
return ans;
}
# | 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... |