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 <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
#include <map>
using namespace std;
#define N 5010
#define ff first
#define ss second
#define ll long long
#define pb push_back
#define mod 1000000007
#define pii pair <int, int>
#define sz(a) int(a.size())
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
ll bigmod(ll a,ll e) {if(e==0)return 1;ll x=bigmod(a*a%mod,e>>1);return e&1?x*a%mod:x;}
int n, m;
int A[N];
int vis[N];
vector <int> E[N], T[N];
vector <int> who_wins(vector <int> a, vector <int> r, vector <int> u, vector <int> v)
{
n = sz(a), m = sz(u);
for(int i = 0; i < m; i++) E[u[i]].pb(v[i]), T[v[i]].pb(u[i]);
queue <int> Q;
for(int i = 0; i < n; i++) {
if(r[i] == 0) continue;
int ok = 0, ok2 = 1;
for(auto h: E[i]) {
if(i == h) ok = 1;
else ok2 = 0;
}
if(ok == 1 && (a[i] == 1 || ok2 == 1)) Q.push(i), vis[i] = 1;
}
while(!Q.empty()) {
int nd = Q.front();
Q.pop();
A[nd] = 1;
for(auto i: T[nd]) {
if(vis[i] == 1) continue;
int ok = 1;
if(a[i] == 0) for(auto j: E[i]) if(j == i) ok = 0;
if(ok == 1 || r[i] == 1) vis[i] = 1, Q.push(i);
}
}
vector <int> ret;
for(int i = 0; i < n; i++) ret.pb(A[i]);
return ret;
}
# | 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... |