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;
int n, m;
int deg[N];
vector<int> R[N];
bool used[N][N];
int cnt[N][N];
vector<int> who_wins(vector<int> A, vector<int> C, vector<int> U, vector<int> V)
{
// input
n = A.size();
m = U.size();
for (int i = 0; i < m; ++i) {
++deg[U[i]];
R[V[i]].push_back(U[i]);
}
// winning position
vector<int> ans(n, 1);
queue<pii> Q;
for (int i = 0; i < n; ++i) {
used[i][0] = true;
Q.emplace(i, 0);
}
while (!Q.empty()) {
int u = Q.front().first, p = Q.front().second;
Q.pop();
if (C[u] && p < n)
continue;
if (p == n)
ans[u] = 0;
int pl = 1, pr = n;
if (!C[u]) {
pl = p+1;
pr = min(p+1, n);
}
for (auto v : R[u]) {
for (int np = pl; np <= pr; ++np) {
++cnt[v][np];
if (cnt[v][np] == (A[v] ? (int)deg[v] : 1) && !used[v][np]) {
used[v][np] = true;
Q.emplace(v, np);
}
}
}
}
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... |