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;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 5000;
const int MAXM = 20000;
int N, M, A[MAXN+10], R[MAXN+10], ans[MAXN+10];
vector<int> adj[MAXN+10], radj[MAXN+10];
bool vis[MAXN+10];
void dfs(int now)
{
vis[now]=1;
for(int nxt : adj[now])
{
if(vis[nxt]) continue;
dfs(nxt);
}
}
void rdfs(int now)
{
vis[now]=1;
for(int nxt : radj[now])
{
if(vis[nxt]) continue;
rdfs(nxt);
}
}
vector<int> who_wins(vector<int> _A, vector<int> _R, vector<int> _U, vector<int> _V)
{
N=_A.size(); M=_U.size();
for(int i=1; i<=N; i++)
{
A[i]=_A[i-1];
R[i]=_R[i-1];
}
for(int i=0; i<M; i++)
{
int u=_U[i]+1, v=_V[i]+1;
adj[u].push_back(v);
radj[v].push_back(u);
}
for(int i=1; i<=N; i++)
{
if(!R[i]) continue;
for(int j=1; j<=N; j++) vis[j]=0;
dfs(i);
bool flag=false;
for(auto nxt : radj[i])
{
if(vis[nxt])
{
flag=true;
break;
}
}
if(!flag) continue;
for(int j=1; j<=N; j++) vis[j]=0;
rdfs(i);
for(int j=1; j<=N; j++) if(vis[j]) ans[j]=1;
}
vector<int> _ans(N);
for(int i=1; i<=N; i++) _ans[i-1]=ans[i];
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... |