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;
vector<int>a, r;
vector<int>adj[5005];
int n, m;
bool vis[5005], cycle[5005], una;
void dfs(int x){
if(!una) vis[x]=true;
una=false;
for(int y:adj[x]){
if(!vis[y] && r[y]==0) dfs(y);
}
}
void dfs2(int x){
vis[x]=true;
for(int y:adj[x]){
if(!vis[y]) dfs2(y);
}
}
vector<int> who_wins(vector<int> _a, vector<int> _r, vector<int> u, vector<int> v){
n=_a.size(), m=u.size();
a=_a, r=_r;
for(int i=0;i<m;i++){
adj[u[i]].push_back(v[i]);
}
for(int i=0;i<n;i++){
if(r[i]==0){
una=true;
memset(vis, false, sizeof vis);
dfs(i);
if(vis[i]) cycle[i]=true;
}
}
vector<int>ans;
for(int i=0;i<n;i++){
bool good=false;
memset(vis, false, sizeof vis);
una=false;
dfs2(i);
for(int i=0;i<n;i++){
if(cycle[i] && vis[i]) good=true;
}
if(good) ans.push_back(0);
else ans.push_back(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... |