#include "train.h"
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <queue>
using namespace std;
const int N = 5e3 + 7;
int n, m;
unordered_set<int> R;
vector<int> g[N], g1[N];
vector<int> A;
void rev(vector<bool> &fi){
for (auto &it : fi)
it = !it;
}
void Fw(int w, vector<bool> &fi){
static queue<int> q;
for (int i = 0; i < fi.size(); i++)
if (fi[i])
q.push(i);
while (!q.empty()){
auto it = q.front(); q.pop();
for (auto to : g1[it]){
if (fi[to])
continue;
if (A[to] == w || all_of(g[to].begin(), g[to].end(), [&](int x){return fi[x] == 1; }))
{
fi[to] = true;
q.push(to);
}
}
}
}
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
::n = a.size();
::A = a;
::m = u.size();
vector<int> res;
vector<bool> R;
for (auto it : r)
R.push_back(it);
for (int i = 0; i < m; ++i){
g[u[i]].push_back(v[i]);
g1[v[i]].push_back(u[i]);
}
while (true){
static vector<bool> X;
X = R;
Fw(1, X);
rev(X);
Fw(0, X);
int cnt = 0;
for (int i = 0; i < n; i++)
if (R[i] && X[i])
{
cnt++;
R[i] = false;
}
if (cnt == 0){
auto ans = vector<int>(n, 1);
for (int i = 0; i < n; i++)
if (X[i])
ans[i] = 0;
return ans;
}
}
return res;
}
Compilation message
train.cpp: In function 'void rev(std::vector<bool>&)':
train.cpp:18:18: error: cannot bind non-const lvalue reference of type 'std::_Bit_reference&' to an rvalue of type 'std::_Bit_iterator::reference {aka std::_Bit_reference}'
for (auto &it : fi)
^~
train.cpp: In function 'void Fw(int, std::vector<bool>&)':
train.cpp:24:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < fi.size(); i++)
~~^~~~~~~~~~~