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;
const int N = 5005;
int n, deg[N], cur[N];
vector<int> adj[N], rev[N];
bool z[N];
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
vector<int> res;
for(int i=0;i<(int)u.size();i++) {
adj[u[i]].push_back(v[i]);
rev[v[i]].push_back(u[i]);
deg[u[i]]++;
}
n = a.size();
for(int i=0;i<n;i++) {
z[i] = r[i];
}
while(true) {
queue<int> q;
res.clear();
for(int i=0;i<n;i++) {
cur[i] = 0;
res.push_back(z[i]);
if(z[i]) q.push(i);
}
while(!q.empty()) {
int C = q.front();
q.pop();
for(auto &T : rev[C]) {
++cur[T];
if(!res[T] && ((a[T] && cur[T] == 1) || (!a[T] && cur[T] == deg[T]))) {
res[T] = true;
q.push(T);
}
}
}
bool upd = false;
for(int i=0;i<n;i++) {
if(!z[i]) continue;
int C = 0;
for(auto &T : adj[i]) {
C += res[T];
}
if((a[i] && C == 0) || (!a[i] && C != deg[i])) {
z[i] = false;
upd = true;
}
}
if(!upd) break;
}
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... |