#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fo(i, n) for(ll i = 0; i<(n); i++)
#define F first
#define S second
#define pb push_back
#define deb(x) cout << #x << " = " << (x) << endl
#define deb2(x, y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pl;
typedef vector<pl> vpl;
ll n;
vl topo;
int seen[6000];
vvl adj(6000);
vvl adjR(6000);
int toposort(int u){
if(seen[u]) return;
seen[u] = 1;
for(auto &v : adj[u]){
toposort(v);
}
topo.pb(u);
}
int c = 0;
int dfs(int u){
if(seen[u]) return 0;
seen[u] = c;
ll ans = 1;
for(auto &v : adj[u]){
ans+=dfs(v);
}
return ans;
}
vector<int> res;
void dfs2(int u){
if(!res[u]) return;
res[u] = 0;
for(auto &v : adjR[u]){
dfs2(v);
}
}
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
n = a.size();
ll m = u.size();
vl selfEdge(n+1, 0);
fo(i, m){
if(u[i] == v[i]) selfEdge[u[i]] = 1;
else{
if(!r[i])adj[u[i]].pb(v[i]);
adjR[v[i]].pb(u[i]);
}
}
memset(seen, 0, sizeof(seen));
fo(i, n){
if(seen[i]) continue;
toposort(i);
}
reverse(all(topo));
memset(seen, 0, sizeof(seen));
vl good;
fo(i, n){
if(seen[i]) continue;
c++;
ll siz = dfs(i);
if(siz>1 || selfEdge[i]) good.pb(i);
}
res.assign(n, 1);
fo(i, good.size()){
dfs2(good[i]);
}
return res;
}
Compilation message
train.cpp: In function 'int toposort(int)':
train.cpp:27:17: error: return-statement with no value, in function returning 'int' [-fpermissive]
27 | if(seen[u]) return;
| ^~~~~~
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:5:33: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
5 | #define fo(i, n) for(ll i = 0; i<(n); i++)
| ^
train.cpp:86:5: note: in expansion of macro 'fo'
86 | fo(i, good.size()){
| ^~
train.cpp: In function 'int toposort(int)':
train.cpp:32:12: warning: control reaches end of non-void function [-Wreturn-type]
32 | topo.pb(u);
| ~~~~~~~^~~