# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
834748 | 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<vector<int>>>a;
int mn = 1e9;
vector<int>tmp(n);
for(int i = 0; i < m; i++){
a[v[i]][c[i]].push_back(u[i]);
a[u[i]][c[i]].push_back(v[i]);
}
for(int i = 0; i < n; i++){
vector<int>vis(n,-1);
queue<int>q;
set<int>keys;
q.push(i);
while(!q.empty()){
int node = q.front();
q.pop();
if(vis[node] == keys.size()) continue;
keys.insert(r[node]);
vis[node] = key.size();
for(int key : keys){
while(a[node][key].size() > 0){
q.push(a[node][key].back());
a[node][key].pop_back();
}
}
}
for(int i = 0; i < n; i++){
if(vis[i] != -1) tmp[i]++;
}
mn = min(mn,tmp[i]);
}
for(int i = 0; i < n; i++){
if(tmp[i] == mn) ans[i] = 1;
else ans[i] = 0;
}
return ans;
}