# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
33692 | mohammad_kilani | Toy Train (IOI17_train) | C++14 | 2000 ms | 2952 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 <bits/stdc++.h>
#include "train.h"
using namespace std;
const int N = 5010;
bool win[N];
int vis[N];
int vi = 0;
vector<int> g[N];
vector<int> r;
bool DFS(int node,int source){
if(vis[node] == vi) return false;
if(r[node]) return false;
vis[node] = vi;
if(node == source) return true;
for(int i=0;i<g[node].size();i++){
if(DFS(g[node][i],source)) return true;
}
return false;
}
bool DFS2(int node){
if(win[node]) return true;
if(vis[node] == vi) return false;
vis[node] = vi;
for(int i=0;i<g[node].size();i++){
if(DFS2(g[node][i])) return true;
}
return false;
}
std::vector<int> who_wins(std::vector<int> a, std::vector<int> R, std::vector<int> u, std::vector<int> v) {
vector<int> ans;
r = R;
int n = a.size();
for(int i=0;i<u.size();i++) g[u[i]].push_back(v[i]);
for(int i=0;i<n;i++){
for(int j=0;j<g[i].size();j++){
vi++;
if(DFS(g[i][j],i)) win[i] = 1;
}
}
for(int i=0;i<n;i++){
vi++;
if(DFS2(i)) win[i] = 1;
ans.push_back(win[i] ^ 1);
}
return ans;
}
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... |