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 "train.h"
#include <bits/stdc++.h>
#define Loop(x,l,r) for (long long x = (l); x < (r); ++x)
typedef long long ll;
typedef std::pair<ll,ll> pll;
using namespace std;
const int N = 5050;
vector<int> A[N];
int col[N];
bool charg[N];
int n, m;
int win[N];
bool vis[N];
int height[N];
bool dfs(int v, int h, int mxc)
{
height[v] = h;
vis[v] = 1;
if (charg[v])
mxc = h;
bool ans = col[v]? 0: 1;
for (int u : A[v]) {
bool wu;
if (vis[u])
wu = win[u] == 1 || height[u] <= mxc;
else
wu = dfs(u, h+1, mxc);
if (col[v])
ans |= wu;
else
ans &= wu;
}
win[v] = ans;
return ans;
}
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> V, std::vector<int> U) {
n = a.size();
m = V.size();
Loop (i,0,n) {
col[i] = a[i];
charg[i] = r[i];
}
Loop (i,0,m) {
int v = V[i], u = U[i];
A[v].push_back(u);
}
vector<int> ans(n);
Loop (i,0,n) {
memset(win, -1, sizeof(win));
memset(vis, 0, sizeof(vis));
memset(height, 0, sizeof(height));
ans[i] = dfs(i, 0, -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... |