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 <bits/stdc++.h>
//#include "train.h"
using namespace std;
typedef long long ll;
typedef double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
#define pb push_back
#define popb pop_back
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
const int nax = 5004;
const int MOD = 1e9 + 7;
int n, m ;
vi adj[nax], rev_adj[nax];
int cnt[nax], sz[nax];
vi who_wins(vi a, vi r, vi u, vi v)
{
n = a.size();
m = u.size();
for(int i= 0; i < m; i ++)
{
adj[u[i]].pb(v[i]);
rev_adj[v[i]].pb(u[i]);
}
for(int i = 0 ; i < n; i ++ )
sz[i] = (int)(adj[i].size());
vi ans(n, 0);
for(int org = 0; org < n; org ++)
{
if(!r[org])
continue;
set<int> cur;
memset(cnt,0,sizeof(cnt));
cur.insert(org);
for(auto o: rev_adj[org])
cnt[o]++;
for(int i = 0 ; i < n; i++)
{
set<int> nw;
for(int j= 0; j < n; j ++)
{
if(cur.count(j) !=0 || nw.count(j) != 0)
continue;
if(a[j])
{
if(cnt[j] > 0)
nw.insert(j);
}
else
{
if(cnt[j] == sz[j])
nw.insert(j);
}
}
for(auto e: nw)
{
for(auto o: rev_adj[e])
cnt[o] ++ ;
cur.insert(e);
}
}
if(a[org])
{
if(cnt[org] > 0 )
{
for(auto e: cur)
ans[e] = 1;
}
}
else
{
if(cnt[org] == sz[org])
for(auto e: cur)
ans[e] = 1;
}
}
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... |