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 <stdio.h>
using namespace std;
vector < int > Next[5005],Next2[5005],ans,P,W;
bool have1[5005][5005];
bool can[5005];
bool have2[5][5005];
bool vis[5005];
bool F(int st,int here,int deg)
{
int ok=0,t;
//printf("%d %d %d\n",st,here,deg);
vis[here]=1;
if(here==st&°) return 1;
if(have1[st][here]) return can[here];
have1[st][here]=1;
for(auto i:Next[here])
{
t=F(st,i,deg+1);
if(W[here]==t) ok=1;
}
if(ok) can[here]=W[here];
else can[here]=1-W[here];
return can[here];
}
void F2(int here,int xx)
{
if(have2[xx][here]) return;
have2[xx][here]=1;
for(auto i:Next2[here]) F2(i,xx);
}
vector < int > who_wins(vector < int > who, vector < int > power, vector < int > u, vector < int > v)
{
P=power;
W=who;
int N=who.size(),M=u.size(),i;
for(i=0;i<N;i++) ans.push_back(0);
for(i=0;i<M;i++) Next[u[i]].push_back(v[i]);
for(i=0;i<M;i++) Next2[v[i]].push_back(u[i]);
for(i=0;i<N;i++) if(power[i]) F(i,i,0);
for(i=0;i<N;i++) if(vis[i]) F2(i,can[i]);
for(i=0;i<N;i++)
{
if(vis[i]) ans[i]=can[i];
else if(have2[0][i]&&have2[1][i]) ans[i]=who[i];
else if(have2[0][i]) ans[i]=0;
else ans[i]=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... |