This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<int>edge[5005],redge[5005];
int cnt[5005];
bool used[5005];
bool solve_one(vector<int>a,int V,vector<int>u,vector<int>v){
/* int cntt = 0;
rep(i,r.size()) cntt += r[i];
if(cntt != 1) return vector<int>();
int V;
rep(i,r.size()) if(r[i]) V = i;
//cout << V << endl;*/
rep(i,5005){
edge[i].clear();
redge[i].clear();
cnt[i] = used[i] = 0;
}
rep(i,u.size()){
edge[u[i]].pb(v[i]);
redge[v[i]].pb(u[i]);
cnt[u[i]]++;
}
queue<int>que; used[V] = 1;
rep(i,redge[V].size()){
int to = redge[V][i]; //cout << to << endl;
if(a[to] == 1) que.push(to);
else{
cnt[to]--;
if(cnt[to] == 0) que.push(to);
}
}
bool ok = 0;
while(!que.empty()){
int q = que.front(); que.pop(); //cout << q << endl;
if(q == V) ok = 1;
if(used[q]) continue; used[q] = 1;
rep(i,redge[q].size()){
int to = redge[q][i];
if(a[to] == 1) que.push(to);
else{
cnt[to]--;
if(cnt[to] == 0) que.push(to);
}
}
}
return ok;
/*if(!ok){
vector<int>ret; rep(i,a.size()) ret.pb(0);
return ret;
}
else{
vector<int>ret; rep(i,a.size()) if(!used[i]) ret.pb(0);else ret.pb(1);
return ret;
}*/
}
bool have[5005];
vector<int>who_wins(vector<int>a,vector<int>r,vector<int>u,vector<int>v){
rep(i,r.size()){
if(r[i] == 1){
have[i] = 1;
}
}
queue<int>A_win;
rep(i,r.size()){
if(!have[i]) continue;
bool flag = solve_one(a,i,u,v);
if(flag) A_win.push(i);
}
rep(i,5005){
edge[i].clear();
redge[i].clear();
cnt[i] = used[i] = 0;
}
rep(i,u.size()){
edge[u[i]].pb(v[i]);
redge[v[i]].pb(u[i]);
cnt[u[i]]++;
}
while(!A_win.empty()){
int q = A_win.front(); A_win.pop();
if(used[q]) continue; used[q] = 1;
rep(i,redge[q].size()){
int to = redge[q][i];
if(a[to] == 1) A_win.push(to);
else{
cnt[to]--;
if(cnt[to] == 0) A_win.push(to);
}
}
}
vector<int>ret; rep(i,a.size()) if(!used[i]) ret.pb(0);else ret.pb(1);
return ret;
}
/*int main(){
vector<int>a,r,u,v;
int n,m;
cin>>n>>m;
rep(i,n) {int x;cin>>x;a.pb(x);}
rep(i,n) {int x;cin>>x;r.pb(x);}
rep(i,m) {int x,y;cin>>x>>y;u.pb(x);v.pb(y);}
auto A = who_wins(a,r,u,v);
rep(i,n) cout << A[i] << endl;
}*/
Compilation message (stderr)
train.cpp: In function 'bool solve_one(std::vector<int>, int, std::vector<int>, std::vector<int>)':
train.cpp:20:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define rep(i,x) for(int i=0;i<x;i++)
train.cpp:41:6:
rep(i,u.size()){
~~~~~~~~~~
train.cpp:41:2: note: in expansion of macro 'rep'
rep(i,u.size()){
^~~
train.cpp:20:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define rep(i,x) for(int i=0;i<x;i++)
train.cpp:47:6:
rep(i,redge[V].size()){
~~~~~~~~~~~~~~~~~
train.cpp:47:2: note: in expansion of macro 'rep'
rep(i,redge[V].size()){
^~~
train.cpp:59:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if(used[q]) continue; used[q] = 1;
^~
train.cpp:59:25: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
if(used[q]) continue; used[q] = 1;
^~~~
train.cpp:20:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define rep(i,x) for(int i=0;i<x;i++)
train.cpp:60:7:
rep(i,redge[q].size()){
~~~~~~~~~~~~~~~~~
train.cpp:60:3: note: in expansion of macro 'rep'
rep(i,redge[q].size()){
^~~
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:20:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define rep(i,x) for(int i=0;i<x;i++)
train.cpp:81:6:
rep(i,r.size()){
~~~~~~~~~~
train.cpp:81:2: note: in expansion of macro 'rep'
rep(i,r.size()){
^~~
train.cpp:20:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define rep(i,x) for(int i=0;i<x;i++)
train.cpp:87:6:
rep(i,r.size()){
~~~~~~~~~~
train.cpp:87:2: note: in expansion of macro 'rep'
rep(i,r.size()){
^~~
train.cpp:20:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define rep(i,x) for(int i=0;i<x;i++)
train.cpp:97:6:
rep(i,u.size()){
~~~~~~~~~~
train.cpp:97:2: note: in expansion of macro 'rep'
rep(i,u.size()){
^~~
train.cpp:104:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if(used[q]) continue; used[q] = 1;
^~
train.cpp:104:25: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
if(used[q]) continue; used[q] = 1;
^~~~
train.cpp:20:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define rep(i,x) for(int i=0;i<x;i++)
train.cpp:105:7:
rep(i,redge[q].size()){
~~~~~~~~~~~~~~~~~
train.cpp:105:3: note: in expansion of macro 'rep'
rep(i,redge[q].size()){
^~~
train.cpp:20:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define rep(i,x) for(int i=0;i<x;i++)
train.cpp:114:22:
vector<int>ret; rep(i,a.size()) if(!used[i]) ret.pb(0);else ret.pb(1);
~~~~~~~~~~
train.cpp:114:18: note: in expansion of macro 'rep'
vector<int>ret; rep(i,a.size()) if(!used[i]) ret.pb(0);else ret.pb(1);
^~~
# | 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... |