#include "train.h"
#include <algorithm>
#include <vector>
#include <unordered_set>
using namespace std;
const int N = 5006;
int n, m;
vector<int> g[N],ing[N];
bool col[N],chrg[N];
unordered_set <int> R;
unordered_set<int> rev(unordered_set<int> &s){
unordered_set<int> ans;
for (int i = 0; i < n; i++){
if (s.count(i) == 0) ans.insert(i);
}
return ans;
}
unordered_set<int> fa(unordered_set<int> &s){
unordered_set<int> ans;
queue<int> q;
for (auto k : s){
q.push(k);
ans.insert(k);
}
while (!q.empty()){
int v = q.front();
q.pop();
for (auto to : ing[v]){
if (ans.count(to)) continue;
bool mb = true;
for (auto k : g[to]){
mb &= ans.count(k) == 1;
}
if (col[to] || mb){
ans.insert(to);
q.push(to);
}
}
}
return ans;
}
unordered_set<int> fb(unordered_set<int> &s){
unordered_set<int> ans;
queue<int> q;
for (auto k : s){
q.push(k);
ans.insert(k);
}
while (!q.empty()){
int v = q.front();
q.pop();
for (auto to : ing[v]){
if (ans.count(to)==1) continue;
bool mb = true;
for (auto k : g[to]){
mb &= ans.count(k) == 1;
}
if (!col[to] || mb){
ans.insert(to);
q.push(to);
}
}
}
return ans;
}
unordered_set<int> intersect(unordered_set<int> &a, unordered_set<int> &b){
unordered_set<int> ans;
for (auto i : a){
if (b.count(i)) ans.insert(i);
}
return ans;
}
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
n = a.size();
m = u.size();
for (int i = 0; i < m; i++){
g[u[i]].push_back(v[i]);
ing[v[i]].push_back(u[i]);
}
for (int i = 0; i < n; i++){
if (a[i]){
col[i] = true;
}
}
for (int i = 0; i < n; i++){
if (r[i]) chrg[i] = true;
}
while (1){
R.clear();
for (int i = 0; i < n; i++){
if (chrg[i]) R.insert(i);
}
unordered_set <int> far = fa(R),gg=rev(far),x = fb(gg), ht = intersect(far, x);
bool mb = false;
for (auto k : ht){
if (chrg[k]) mb = true, chrg[k] = false;
}
if (!mb){
vector<int> ans(n,1);
for (auto k : x){
ans[k] = 0;
}
return ans;
}
}
}
/*
2 4
0 1
1 0
0 0
0 1
1 0
1 1
*/
Compilation message
train.cpp: In function 'std::unordered_set<int> fa(std::unordered_set<int>&)':
train.cpp:22:2: error: 'queue' was not declared in this scope
queue<int> q;
^~~~~
train.cpp:22:8: error: expected primary-expression before 'int'
queue<int> q;
^~~
train.cpp:24:3: error: 'q' was not declared in this scope
q.push(k);
^
train.cpp:27:10: error: 'q' was not declared in this scope
while (!q.empty()){
^
train.cpp: In function 'std::unordered_set<int> fb(std::unordered_set<int>&)':
train.cpp:47:2: error: 'queue' was not declared in this scope
queue<int> q;
^~~~~
train.cpp:47:8: error: expected primary-expression before 'int'
queue<int> q;
^~~
train.cpp:49:3: error: 'q' was not declared in this scope
q.push(k);
^
train.cpp:52:10: error: 'q' was not declared in this scope
while (!q.empty()){
^