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 <bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vi>
#define vb vector<bool>
#define vvb vector<vb>
#define ii pair<int, int>
#define x first
#define y second
#define vii vector<ii>
#define pb push_back
#define all(x) x.begin(), x.end()
#define loop(i,s,e) for(int i=s;i<e;++i)
#define loopr(i,s,e) for(int i=e-1;i>=s;--i)
#define chkmin(a,b) a = min(a,b)
#define chkmax(a,b) a = max(a,b)
using namespace std;
const int INF = 1e9;
int n;
vb check;
void dfs(int cur, vi& vec, vvi& g){
if (check[cur]) return ;
check[cur] = 1;
for(auto nei:g[cur]) dfs(nei, vec, g);
vec.pb(cur);
}
vvi g, ag;
vi who_wins(vi a, vi r, vi u, vi v) {
n = a.size();
g.resize(n); ag.resize(n); check.resize(n);
loop(i,0,u.size()){
int a = u[i], b = v[i];
g[a].pb(b);
ag[b].pb(a);
}
vi order;
loop(i,0,n) dfs(i, order, ag);
reverse(all(order));
fill(all(check),0);
vi res(n);
for(auto cur:order){
if (check[cur]) continue;
vi vec;
dfs(cur, vec, g);
/*for(auto i:vec) cout<<i<<" ";
cout<<endl;*/
bool good = 0;
for(auto i:vec) if (r[i]) good = 1;
if (vec.size()==1){
bool self = 0;
for(auto nei:g[vec[0]]) if (nei==vec[0]) self = 1;
if (!self) good = 0;
}
if (!good){
for(auto c:vec) for(auto nei:g[c]){
if (res[nei]) good = 1;
}
}
for(auto i:vec) res[i] = good;
}
return res;
}
/*
clear
g++ c.cpp grader.cpp -o c ; ./c
6 7
1 1 1 1 1 1
1 0 0 0 0 1
0 1
1 2
2 3
3 1
4 5
5 5
4 1
*/
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:12:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
12 | #define loop(i,s,e) for(int i=s;i<e;++i)
......
34 | loop(i,0,u.size()){
| ~~~~~~~~~~~~
train.cpp:34:5: note: in expansion of macro 'loop'
34 | loop(i,0,u.size()){
| ^~~~
# | 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... |