#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]++;
assert(outwin[re] <= edg[re].size());
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]--;
if (!a[re] && outwin[re] == edg[re].size() - 1) rWin.push(re);
else if (a[re] && outwin[re] == 0) rWin.push(re);
}
}
return res;
}
/*
int main(){
auto ret = who_wins({0, 0, 0, 1, 1, 0, 1}, {0, 0, 0, 1, 1, 1, 0}, {0, 1, 1, 2, 3, 4, 5, 5, 6}, {0, 1, 2, 3, 3, 4, 5, 6, 6});
for (int i : ret) cout << i << " ";
return 0;
}*/
Compilation message
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:17:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for (int i = 0; i < u.size(); ++i) {
| ~~^~~~~~~~~~
In file included from /usr/include/c++/10/cassert:44,
from train.cpp:4:
train.cpp:32:31: 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 | assert(outwin[re] <= edg[re].size());
train.cpp:34: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]
34 | else if (!a[re] && outwin[re] == edg[re].size()) addWin.push(re);
train.cpp:41:41: 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]
41 | else if (!a[i] && outwin[i] < edg[i].size()) rWin.push(i);
train.cpp:51:38: 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]
51 | if (!a[re] && outwin[re] == edg[re].size() - 1) rWin.push(re);
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
1024 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
0 ms |
212 KB |
3rd lines differ - on the 4th token, expected: '0', found: '1' |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
1364 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1236 KB |
Output is correct |
2 |
Correct |
5 ms |
1236 KB |
Output is correct |
3 |
Correct |
6 ms |
1332 KB |
Output is correct |
4 |
Correct |
6 ms |
1364 KB |
Output is correct |
5 |
Correct |
6 ms |
1388 KB |
Output is correct |
6 |
Correct |
6 ms |
1296 KB |
Output is correct |
7 |
Correct |
5 ms |
1280 KB |
Output is correct |
8 |
Correct |
5 ms |
1236 KB |
Output is correct |
9 |
Correct |
5 ms |
1236 KB |
Output is correct |
10 |
Correct |
6 ms |
1364 KB |
Output is correct |
11 |
Correct |
6 ms |
1364 KB |
Output is correct |
12 |
Correct |
6 ms |
1344 KB |
Output is correct |
13 |
Correct |
6 ms |
1364 KB |
Output is correct |
14 |
Correct |
5 ms |
1236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1364 KB |
Output is correct |
2 |
Correct |
6 ms |
1364 KB |
Output is correct |
3 |
Correct |
6 ms |
1364 KB |
Output is correct |
4 |
Correct |
5 ms |
1236 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
3 ms |
980 KB |
Output is correct |
7 |
Correct |
4 ms |
852 KB |
Output is correct |
8 |
Incorrect |
4 ms |
852 KB |
3rd lines differ - on the 5th token, expected: '0', found: '1' |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
1024 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |