# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
836161 | kamelfanger83 | Toy Train (IOI17_train) | C++14 | 9 ms | 1436 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 <vector>
#include <iostream>
#include <queue>
#include <cassert>
#include "train.h"
using namespace std;
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v){
int n = a.size();
vector<vector<int>> edg (n), revedg (n);
vector<int> recharg;
for (int i = 0; i < n; ++i) {
if (r[i]) recharg.push_back(i);
}
for (int i = 0; i < u.size(); ++i) {
edg[u[i]].push_back(v[i]);
revedg[v[i]].push_back(u[i]);
}
queue<int> addWin;
for (int i : recharg) addWin.push(i);
vector<int> res (n);
vector<int> outwin (n);
while(!addWin.empty()){
int i = addWin.front();
addWin.pop();
if (res[i]) continue;
res[i] = true;
for (int re : revedg[i]){
outwin[re]++;
if (a[re] && outwin[re] == 1) addWin.push(re);
else if (!a[re] && outwin[re] == edg[re].size()) addWin.push(re);
}
}
queue<int> rWin;
for (int i : recharg){
if (res[i]){
if (a[i] && !outwin[i]) rWin.push(i);
else if (!a[i] && outwin[i] < edg[i].size()) rWin.push(i);
}
}
while (!rWin.empty()){
int i = rWin.front();
rWin.pop();
if (!res[i]) continue;
res[i] = false;
for (int re : revedg[i]){
outwin[re]--;
assert(outwin[re] >= 0);
if (!a[re]) rWin.push(re);
else if (outwin[re] == 0) rWin.push(re);
}
}
return res;
}
/*
int main(){
auto ret = who_wins({1, 1}, {0, 1}, {1, 0}, {0, 0});
for (int i : ret) cout << i << " ";
return 0;
}*/
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... |