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];
void Dfs(int v)
{
//cout << v << " : " << endl;
marked[v] = true;
for(auto u : adj[v])
{
//cout << u << endl;
if(u == st)
cyc[st] = true;
if(!dead[u] && !marked[u])
Dfs(u);
}
}
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;
for(int j = 0 ; j < n ; j++)
marked[j] = false;
Dfs(i);
}
for(int i = 0 ; i < n ; i++)
{
memset(marked , false , sizeof marked);
res[i] = (Solve(i) ? 0 : 1);
}
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... |