# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
834727 | IS_Rushdi | 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>
using namespace std;
vector<int> find_reachable(vector<int> r, vector<int> u, vector<int> v, vector<int> c) {
vector<int> ans(r.size(), 1);
int n = r.size();
int m = u.size();
vector<vector<int>>a(n);
vector<int>tmp(n);
for(int i = 0; i < m; i++){
a[v[i]].push_back(u[i]);
a[u[i]].push_back(v[i]);
}
int mn = 1e9;
for(int i = 0; i < n; i++){
vector<bool>vis(n,0);
queue<pair<int,bool>>q;
q.push({i,0});
int c = 0;
while(!q.empty()){
int node = q.front().first;
bool can = q.front().second;
if(vis[node]) continue;
vis[node]=1;
c++;
if(r[node] == 0) can=1;
if(can){
for(int to : a[node]){
q.push({to,can});
}
}
}
tmp[i] = c;
mn = min(mn,c);
}
for(int i = 0; i < n; i++){
if(tmp[i] == mn) ans[i] = 1;
else ans[i] = 0;
}
return ans;
}
int main(){
}