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 <bits/stdc++.h>
using namespace std;
const int N=2001;
int a[N],b[N],d[N],cnt[N];
vector<int> R,C;
vector<vector<pair<int,int>>> g(N),e(N);
void dfs(int v){
d[v]=1;
bool ok=(b[R[v]]==0);
b[R[v]]=1;
if(ok){
for(auto x:e[R[v]]){
if(d[x.first]+d[x.second]==1){
if(d[x.first]){
dfs(x.second);
}
else{
dfs(x.first);
}
}
}
}
for(auto x:g[v]){
if(d[x.first] || b[x.second]==0){
continue;
}
dfs(x.first);
}
}
vector<int> find_reachable(vector<int> r, vector<int> u, vector<int> v, vector<int> c) {
R=r;
C=c;
int n=(int)r.size();
int m=(int)c.size();
for(int i=0;i<m;i++){
g[u[i]].push_back({v[i],c[i]});
g[v[i]].push_back({u[i],c[i]});
e[c[i]].push_back({u[i],v[i]});
}
vector<int> ans(r.size(), 1);
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
a[j]=b[j]=d[j]=0;
}
dfs(i);
for(int j=0;j<n;j++){
cnt[i]+=d[j];
}
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(cnt[i]>cnt[j]){
ans[i]=0;
}
}
}
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... |