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 "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);
}
}
while (true){
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);
}
}
if (rWin.empty()) break;
while (!rWin.empty()){
int i = rWin.front();
rWin.pop();
if (!res[i]) continue;
res[i] = false;
for (int re : revedg[i]){
outwin[re]--;
if (a[re] && outwin[re] == 0) rWin.push(re);
else if (!a[re] && outwin[re] == edg[re].size() - 1) rWin.push(re);
}
}
}
return res;
}
/*
int main(){
auto ret = who_wins({0, 0, 1, 0}, {0, 1, 0, 0}, {0, 1, 1, 2, 2, 3}, {0, 0, 1, 1, 3, 3});
for (int i : ret) cout << i << " ";
return 0;
}*/
Compilation message (stderr)
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:16:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | for (int i = 0; i < u.size(); ++i) {
| ~~^~~~~~~~~~
train.cpp:32:43: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | else if (!a[re] && outwin[re] == edg[re].size()) addWin.push(re);
train.cpp:40:45: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | else if (!a[i] && outwin[i] < edg[i].size()) rWin.push(i);
train.cpp:52:47: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | else if (!a[re] && outwin[re] == edg[re].size() - 1) rWin.push(re);
# | 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... |