# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
116996 | zubec | Toy Train (IOI17_train) | C++14 | 11 ms | 1920 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> g[5010], gg[5010];
int kol[5010];
bool used[5010];
int n, clr[5010], chrg[5010];
bool delt[5010];
vector <pair<int, int> > rebr;
void cler(){
for (int i = 0; i < n; i++){
used[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(vector <int> vec, int c){
cler();
while(!vec.empty()){
int v = vec.back();
vec.pop_back();
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){
vec.push_back(to);
} else
if (kol[to] == 0){
vec.push_back(to);
}
}
}
}
vector <int> vec;
bool solve(){
vector <int> fvec;
for (int i = 0; i < vec.size(); i++){
if (chrg[vec[i]])
fvec.push_back(vec[i]);
}
f(fvec, 0);
fvec.clear();
for (int i = 0; i < vec.size(); i++){
if (!used[vec[i]])
fvec.push_back(vec[i]);
}
f(fvec, 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;
n = a.size();
for (int i = 0; i < n; i++){
g[i].clear();
gg[i].clear();
clr[i] = a[i]^1;
chrg[i] = r[i];
}
for (int i = 0; i < u.size(); i++){
g[u[i]].push_back(v[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... |