# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
126804 | neki | Toy Train (IOI17_train) | C++14 | 2057 ms | 1628 KiB |
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 maxn 5010
#define loop(i, a, b) for(int i=a;i<b;i++)
#define cc(a) cout<< a << endl;
using namespace std;
vector<int> edges[maxn];
vector<int> owner;vector<int> power;
int low[maxn];
int bval[maxn];
int cnt;
bool dfs(int u){
low[u]=cnt; if(power[u]) cnt++;
bval[u]=0;
bool ans=(!(owner[u]));
for(auto&& e:edges[u]){
bool cmp;
if(bval[e]==-1) dfs(e);
if(low[e]!=-1){
if( low[e]!=low[u] or power[u]) cmp=1;
else cmp=0;
}
else{ cmp=bval[e];}
if(owner[u]) ans=ans or cmp;
else ans=ans and cmp;
}
bval[u]=ans;
low[u]=-1;
return ans;
}
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
int n=a.size();
std::vector<int> res(n);
loop(i, 0, u.size()) edges[u[i]].push_back(v[i]);
owner=a;power=r;
loop(i, 0, n){
cnt=0;
loop(j, 0, n) {bval[j]=-1;}
res[i]=dfs(i);
}
return res;
}
Compilation message (stderr)
# | 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... |