# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
265108 | alexandra_udristoiu | Toy Train (IOI17_train) | C++14 | 13 ms | 2048 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<iostream>
#include<vector>
#include<cstring>
#include "train.h"
using namespace std;
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> X, vector<int> Y){
int i, j, n, ok, p, u, nod, vecin;
vector<int> v[5005], sol;
int viz[5005], viz2[5005], c[5005], g[5005], viz3[5005], grad[5005];
n = a.size();
sol.resize(n);
for(i = 0; i < X.size(); i++){
v[ Y[i] ].push_back(X[i]);
grad[ X[i] ]++;
}
for(i = 0; i < n; i++){
viz[i] = 1;
}
while(1){
memset(viz2, 0, sizeof(viz2) );
memset(g, 0, sizeof(g) );
p = 1;
u = 0;
for(i = 0; i < n; i++){
if(viz[i] == 1 && r[i] == 1){
c[++u] = i;
viz2[i] = 1;
}
}
if(u == 0){
break;
}
while(p <= u){
nod = c[p];
p++;
for(i = 0; i < v[nod].size(); i++){
vecin = v[nod][i];
if(viz2[vecin] == 0 && viz[vecin] == 1){
g[vecin]++;
if(a[vecin] == 1 || g[vecin] == grad[vecin]){
c[++u] = vecin;
viz2[vecin] = 1;
}
}
}
}
memset(g, 0, sizeof(g) );
p = 1;
u = 0;
for(i = 0; i < n; i++){
if(viz[i] == 1 && viz2[i] == 0){
c[++u] = i;
viz[i] = 0;
}
}
if(u == 0){
break;
}
while(p <= u){
nod = c[p];
p++;
for(i = 0; i < v[nod].size(); i++){
vecin = v[nod][i];
if(viz[vecin] == 1){
g[vecin]++;
if(a[vecin] == 0 || g[vecin] == grad[vecin]){
c[++u] = vecin;
viz2[vecin] = 1;
}
}
}
}
}
for(i = 0; i < n; i++){
sol[i] = viz[i];
}
return sol;
}
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... |