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("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse3,sse4,popcnt,avx,mmx,abm")
#include "train.h"
#include <bits/stdc++.h>
#define DEBUG 1
using namespace std;
namespace output{
void __(short x){cout<<x;}
void __(unsigned x){cout<<x;}
void __(int x){cout<<x;}
void __(long long x){cout<<x;}
void __(unsigned long long x){cout<<x;}
void __(double x){cout<<x;}
void __(long double x){cout<<x;}
void __(char x){cout<<x;}
void __(const char*x){cout<<x;}
void __(const string&x){cout<<x;}
void __(bool x){cout<<(x?"true":"false");}
template<class S,class T>
void __(const pair<S,T>&x){__(DEBUG?"(":""),__(x.first),__(DEBUG?", ":" "),__(x.second),__(DEBUG?")":"");}
template<class T>
void __(const vector<T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
template<class T>
void __(const set<T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
template<class T>
void __(const multiset<T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
template<class S,class T>
void __(const map<S,T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
void pr(){cout<<"\n";}
template<class S,class... T>
void pr(const S&a,const T&...b){__(a);if(sizeof...(b))__(' ');pr(b...);}
}
using namespace output;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,char> pic;
typedef pair<double,double> pdd;
typedef pair<ld,ld> pld;
typedef vector<int> vi;
typedef vector<ll> vl;
#define pb push_back
#define fox(i,x,y) for(int i=(x);i<=(y);i++)
#define foxr(i,x,y) for(int i=(y);i>=(x);i--)
const int MN = 5005;
int N, M, i, j, x, ok[MN], deg[MN], arr[MN], ch[MN], vs[MN], prop[MN], rf[MN], dn;
vi adj[MN]; queue<int> q;
inline void bfs(){
for(i=0;i<N;i++)
deg[i]=vs[i]=prop[i]=0;
for(i=0;i<N;i++){
for(auto v : adj[i])
deg[v]++;
}
for(i=0;i<N;i++){
rf[i]=ok[i];
if(ok[i]&&ch[i]){
vs[i] = 1;
q.push(i);
}
ok[i]=0;
}
while(q.size()){
x=q.front(); q.pop();
ok[x]=1;
for(auto v : adj[x]){
if(vs[v]) continue;
if(arr[v]||!(--deg[v])){
vs[v]=1;
q.push(v);
}
}
}
int fl=0;
for(i=0;i<N;i++){
if(ok[i]!=rf[i]) fl=1;
}
if(!fl) dn=1;
}
vi who_wins(vi a,vi r,vi u,vi v){
N = (int)a.size();
M = (int)u.size();
for(i=0;i<N;i++)
arr[i]=a[i],ch[i]=r[i];
for(i=0;i<M;i++)
adj[v[i]].pb(u[i]);
memset(ok,1,sizeof(ok));
for(j=0;j<N&&!dn;j++)
bfs();
vi res;
for(i=0;i<N;i++)
res.pb(ok[i]);
return res;
}
# | 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... |