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>
using namespace std;
#define sz(a) (int)(a.size())
const int MAXN = 5555;
vector<int>g[MAXN],gr[MAXN];
std::vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
int n = sz(a);
vector<int>bwin(n,0);
for(int i=0;i<sz(u);i++){
g[u[i]].push_back(v[i]);
gr[v[i]].push_back(u[i]);
}
function<void()>bfs = [&](){
queue<int>q;
vector<int>cnt(n,0),charge(n,0);
for(int i=0;i<n;i++){
if(r[i]){
q.push(i);
charge[i] = 1;
}
cnt[i] = sz(g[i]);
}
while(!q.empty()){
int v = q.front();
q.pop();
for(int x:gr[v]){
if(charge[x])continue;
if(a[x]){
charge[x] = 1;
q.push(x);
}else{
cnt[x]--;
if(cnt[x])continue;
charge[x] = 1;
q.push(x);
}
}
}
for(int i=0;i<n;i++){
if(!charge[i]){
q.push(i);
bwin[i] = 1;
}
}
for(int i=0;i<n;i++){
if(r[i]){
int cnt = 0;
for(int x:g[i])cnt += bwin[x];
if(a[i] && cnt == sz(g[i])){
r[i] = 0;
bwin[i] = 1;
}
if(!a[i] && cnt){
r[i] = 0;
bwin[i] = 1;
}
}
}
};
while(true){
int ncharge = 0;
for(int i=0;i<n;i++)ncharge += r[i];
bfs();
for(int i=0;i<n;i++)ncharge -= r[i];
if(!ncharge)break;
}
for(int i=0;i<n;i++)bwin[i] ^= 1;
return bwin;
}
# | 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... |