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;
vector<int> G[N], R[N];
bool dp[N][N], vis[N][N];
vector<int> *A, *C;
bool solve(int u, int p)
{
if ((*C)[u]) p = n;
if (p == 0) return true;
if (vis[u][p]) return dp[u][p];
vis[u][p] = true;
int cnt = 0;
for (auto v : G[u])
if (solve(v, p-1)) ++cnt;
return dp[u][p] = cnt >= ((*A)[u] ? G[u].size() : 1);
}
vector<int> who_wins(vector<int> A, vector<int> C, vector<int> U, vector<int> V)
{
::A = &A, ::C = &C;
// input
n = A.size();
m = U.size();
for (int i = 0; i < m; ++i) {
G[U[i]].push_back(V[i]);
R[V[i]].push_back(U[i]);
}
vector<int> ans(n, 0);
for (int u = 0; u < n; ++u)
ans[u] = solve(u, n) ? 0 : 1;
return ans;
}
Compilation message (stderr)
train.cpp: In function 'bool solve(int, int)':
train.cpp:22:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
return dp[u][p] = cnt >= ((*A)[u] ? G[u].size() : 1);
~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |