# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
138325 | almogwald | Toy Train (IOI17_train) | C++14 | 12 ms | 1656 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 <utility>
#include <algorithm>
#include "train.h"
#define fori(i,n) for(int i=0;i<n;i++)
#define forib(i,n) for(int i=n-1;i>=0;i--)
#define maxl 10000000000
typedef long long lol;
using namespace 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();
vector<int> res(n,1);
vector<vector<int>> cons(n);
vector<vector<int>> opcons(n);
fori(i,u.size()){
int cur=u[i];
int next=v[i];
cons[cur].push_back(next);
opcons[next].push_back(cur);
}
int cur=0;
vector<int>left(n);
fori(i,n){
if(r[i]){
cur=i;
}
if(a[i]){
left[i]=1;
}else{
left[i]=cons[i].size();
}
}
vector<int> help;
fori(j,opcons[cur].size()){
int curr=opcons[cur][j];
left[curr]--;
if(left[curr]==0){
res[curr]=1;
if(cur!=curr){
help.push_back(curr);
}
}
}
while(help.size()){
int i=help.back();
help.pop_back();
fori(j,opcons[i].size()){
int curr=opcons[i][j];
left[curr]--;
if(left[curr]==0){
res[curr]=1;
if(cur!=curr){
help.push_back(curr);
}
}
}
}
if(res[cur]==0){
fori(i,n){
res[i]=0;
}
}
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... |