# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
116999 | zubec | Toy Train (IOI17_train) | C++14 | 948 ms | 1652 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;
vector <int> gg[5010];
int kol[5010];
bool used[5010];
int n, clr[5010], chrg[5010];
bool delt[5010];
vector <pair<int, int> > rebr;
queue <int> q;
void cler(){
for (int i = 0; i < n; i++){
used[i] = 0;
kol[i] = 0;
}
for (int i = 0; i < rebr.size(); i++){
int u = rebr[i].first, v = rebr[i].second;
if (!delt[u] && !delt[v])
++kol[u];
}
}
void f(int c){
cler();
while(!q.empty()){
int v = q.front();
q.pop();
if (used[v])
continue;
used[v] = 1;
for (int j = 0; j < gg[v].size(); j++){
int to = gg[v][j];
if (delt[to])
continue;
--kol[to];
if (used[to])
continue;
if (clr[to] == c){
q.push(to);
} else
if (kol[to] == 0){
q.push(to);
}
}
}
}
vector <int> vec;
bool solve(){
for (int i = 0; i < vec.size(); i++){
if (chrg[vec[i]])
q.push(vec[i]);
}
f(0);
for (int i = 0; i < vec.size(); i++){
if (!used[vec[i]])
q.push(vec[i]);
}
f(1);
bool bb = 0;
for (int i = vec.size()-1; i >= 0; i--){
if (used[vec[i]]){
bb = 1;
delt[vec[i]] = 1;
swap(vec[i], vec.back());
vec.pop_back();
}
}
return bb;
}
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
vector <int> ansvec;
rebr.clear();
n = a.size();
for (int i = 0; i < n; i++){
gg[i].clear();
delt[i] = 0;
clr[i] = a[i]^1;
chrg[i] = r[i];
}
for (int i = 0; i < u.size(); i++){
gg[v[i]].push_back(u[i]);
rebr.push_back({u[i], v[i]});
}
for (int i = 0; i < n; i++){
vec.push_back(i);
}
while(solve()){
}
ansvec.resize(n);
for (int i = 0; i < vec.size(); i++){
ansvec[vec[i]] = 1;
}
return ansvec;
}
/**
2 4
0 1
1 0
0 0
0 1
1 0
1 1
*/
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... |