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 "train.h"
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define AquA cin.tie(0);ios_base::sync_with_stdio(0);
#define fs first
#define sc second
#define p_q priority_queue
using namespace std;
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
int n=a.size(),m=u.size();
vector<int> vis(n);
vector<vector<int> > e(n);
vector<int> deg(n);
for(int i=0;i<m;i++){
e[v[i]].push_back(u[i]);
deg[u[i]]++;
}
auto find=[&](vector<int>& b,int s){
queue<int> q;
for(auto h:b){
q.push(h);
}
vector<int> ret,v2(n);
auto d=deg;
while(q.size()){
auto h=q.front();
q.pop();
ret.push_back(h);
for(auto u:e[h]){
if(!vis[u] && !v2[u]){
if(a[u]==s){
v2[u]=1;
q.push(u);
}
else{
d[u]--;
if(d[u]==0){
q.push(u);
}
}
}
}
}
return ret;
};
vector<int> ans(n);
while(1){
vector<int> s;
for(int i=0;i<n;i++){
if(!vis[i] && r[i]){
s.push_back(i);
}
}
auto x=find(s,1);
vector<int> p(n);
for(int i=0;i<n;i++){
if(vis[i]){
p[i]=1;
}
}
for(auto h:x){
p[h]=1;
}
vector<int> b;
for(int i=0;i<n;i++){
if(!p[i]){
b.push_back(i);
}
}
if(b.empty()){
for(auto h:x){
ans[h]=1;
}
break;
}
auto c=find(b,0);
for(auto h:c){
vis[h]=1;
for(auto z:e[h]){
deg[z]--;
}
}
}
return ans;
}
# | 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... |