# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
69899 | bnahmad15 | Toy Train (IOI17_train) | C++17 | 1154 ms | 3412 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>
using namespace std;
const int N = 5001;
int n,vis[N],tim[N],cnt = 0;
int is[N],no[N],can[N];
vector <int> g[N];
int dfs(int u,int found){
tim[u] = ++cnt;
vis[u] = 1;
no[tim[u]] = 1;
int res = 0;
if(is[u] == 1)
found = tim[u];
// cout<<u<<" "<<is[u]<<" "<<found<<" "<<cnt<<endl;
for(int i = 0;i<g[u].size();i++){
int v = g[u][i];
if(vis[v] == 2){
// cout<<res<<" ";
continue;
}
else if(vis[v] == 1){
res = max(res,no[found] & (found >= tim[v]) ? 1 : 0);
// cout<<res<<" ";
continue;
}else{
res = max(res,dfs(v,found));
}
// cout<<res<<" ";
}
// cout<<endl;
no[tim[u]] = 0;
vis[u] = 2;
can[u] |= res;
return res;
}
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
std::vector<int> res;
n = a.size();
for(int i = 0;i<n;i++){
is[i] = 0;
}
for(int i = 0;i<r.size();i++){
if(r[i] == 1)
is[i] = 1;
}
for(int i = 0;i<u.size();i++){
g[u[i]].push_back(v[i]);
}
for(int i = 0;i<n;i++){
if(can[i] == 1){
res.push_back(1);
}else{
for(int j = 0;j<n;j++){
vis[j] = 0;
tim[j] = -1;
}
cnt = 0;
res.push_back(dfs(i,-1));
}
// cout<<endl;
}
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... |