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;
const int N = 5e3 + 10;
int n , m , st;
vector <int> adj[N];
bool dead[N] , marked[N] , cyc[N];
bool vis[N][2];
void Dfs(int v , int ty)
{
vis[v][ty] = true;
if(dead[v] && ty == 0)
{
Dfs(v , 1);
return;
}
for(auto u : adj[v])
{
if(u == st && ty == 1)
cyc[st] = true;
if(!vis[u][ty])
Dfs(u , ty);
}
}
bool Solve(int v)
{
marked[v] = true;
if(cyc[v])
return true;
bool flg = false;
for(auto u : adj[v]) if(!marked[u])
flg |= Solve(u);
return flg;
}
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
n = a.size();
m = u.size();
vector<int> res(a.size());
for(int i = 0 ; i < n ; i++)
dead[i] = r[i];
for(int i = 0 ; i < m ; i++)
adj[u[i]].push_back(v[i]);
for(int i = 0 ; i < n ; i++) if(!dead[i])
{
//cout << "DFS " << i << endl;
st = i;
memset(vis , false , sizeof vis);
Dfs(i , 0);
}
for(int i = 0 ; i < n ; i++)
{
memset(marked , false , sizeof marked);
res[i] = Solve(i);
}
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... |