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;
vector<int>tim;
vector<int>s,a,r;
vector<int>adj[200];
vector<int>ans;
int t = 1;
bool dfs(int u) {
if(ans[u])
return 1;
if(tim[u]) {
if(s.back() >= tim[u])
return 1;
return 0;
}
tim[u] = t++;
if(r[u])
s.push_back(t-1);
bool ok;
if(a[u]) {
ok = 0;
for(auto z : adj[u]) {
ok |= dfs(z);
}
} else {
ok = 1;
for(auto z : adj[u]) {
ok &= dfs(z);
}
}
if(r[u])
s.pop_back();
tim[u] = 0;
return ok;
}
vector<int>who_wins(vector<int>A, vector<int>R, vector<int>u, vector<int>v) {
r = R;
a = A;
int n = r.size();
int m = u.size();
for(int i = 0 ; i < m ; i++) {
adj[u[i]].push_back(v[i]);
}
ans.resize(n,0);
for(int i = 0 ; i < n ; i++) {
t = 1;
tim.clear();
tim.resize(n,0);
ans[i] = dfs(i);
}
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... |