This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//In the name of God
#include <bits/stdc++.h>
#include "train.h"
using namespace std;
typedef int ll;
typedef pair<ll, ll> pll;
const ll maxn = 5100;
const ll mod = 1e9 + 7;
const ll inf = 1e9;
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt", "r+", stdin);freopen("output.txt", "w+", stdout);
#define pb push_back
#define Mp make_pair
#define F first
#define S second
#define Sz(x) ll((x).size())
#define all(x) (x).begin(), (x).end()
ll n, m;
vector<ll> g[maxn], gp[maxn];
ll ok[maxn][maxn], cnt[maxn], q[maxn], w[maxn];
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> v, vector<int> u){
n = Sz(a);
m = Sz(v);
vector<int> res(n), res2(n);
for(ll i = 0; i < m; i++){
g[v[i]].pb(u[i]);
gp[u[i]].pb(v[i]);
}
/*res2[n - 1] = r[n - 1];
for(ll i = n - 1; i--;){
res2[i] = res2[i + 1];
if(Sz(g[i]) == 1) continue;
if(a[i]) res2[i] |= r[i];
else res2[i] &= r[i];
}*/
for(ll i = 0; i < n; i++){
if(!r[i]) continue;
fill(cnt, cnt + maxn, 0);
ll l = 0, r = 0;
ok[i][q[r++] = i] = 1;
while(l < r){
ll v = q[l++];
for(ll u : gp[v]){
cnt[u]++;
if(ok[i][u]) continue;
if(a[u]) ok[i][q[r++] = u] = 1;
else if(cnt[u] == Sz(g[u])) ok[i][q[r++] = u] = 1;
}
}
if(a[i]){
if(cnt[i]) w[i] = 1;
}
else{
if(cnt[i] == Sz(g[i])) w[i] = 1;
}
}
fill(cnt, cnt + n, 0);
ll l = 0, qr = 0;
for(ll i = 0; i < n; i++){
if(w[i]){
res[q[qr++] = i] = 1;
continue;
}
if(!r[i]) continue;
for(ll j : g[i]){
if(i == j) cnt[i]++;
}
if(cnt[i] == Sz(g[i]) || (a[i] && cnt[i])) res[q[qr++] = i] = 1;
}
while(l < qr){
ll v = q[l++];
for(ll u : gp[v]){
cnt[u]++;
if(res[u]) continue;
if(a[u] || cnt[u] == Sz(g[u])) res[q[qr++] = u] = 1;
}
}
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... |