# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
534764 | Icebear16 | Keys (IOI21_keys) | C++17 | 0 ms | 0 KiB |
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>
std::vector<int> adj[2000];
std::vector<bool> visited(2000,false);
int k=0;
set<int> s;
void dfs(int u){
if(visited[u]){
return;
}else{
visited[u]=true;
s.insert(r[u]);
k+=1;
// std::cout<<u<<" ";
}
for(int i=0;i<adj[u].size();i++){
if(s.count())
int v=adj[u][i];
dfs(v);
}
}
std::vector<int> find_reachable(std::vector<int> r, std::vector<int> u, std::vector<int> v, std::vector<int> c) {
std::vector<int> ans(r.size(), 1);
for(int i=0;i<u.size();i++){
adj[u[i]].push_back(v[i]);
// adj[v[i]].push_back(u[i]);
}
for(int i=0;i<r.size();i++){
// std::cout<<std::endl;
s.insert(r[i]);
dfs(i);
// std::cout<<k<<std::endl;
ans[i]=k;
k=0;
for(int j=0;j<r.size();j++){
visited[j]=false;
}
}
int m=1000000;
for(int i=0;i<r.size();i++){
m=std::min(m,ans[i]);
}
// return ans;
for(int i=0;i<r.size();i++){
if(ans[i]==m){
ans[i]=1;
}else{
ans[i]=0;
}
}
return ans;
}