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(n,vector<vector<int>>(n,vector<int>()));
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]);
}
int mn = 2e9;
vector<int>cnt(n);
for(int i = 0; i < n; i++){
vector<bool>vis(n);
vector<bool>vis2(n);
vector<vector<int>>arr(n,vector<int>());
vector<int>keys;
queue<int>q;
q.push(i);
while(!q.empty()){
int node = q.front();
q.pop();
if(vis[node]) continue;
vis[node]=1;
if(!vis2[r[node]]){
keys.push_back(r[node]);
vis2[r[node]]=1;
for(int to : arr[r[node]]){
q.push(to);
}
}
for(int j = 0; j < n; j++){
if(!vis2[j]){
for(int to : a[node][j]){
arr[j].push_back(to);
}
}
else{
for(int to : a[node][j]){
q.push(to);
}
}
}
}
for(int j = 0; j < n; j++){
if(vis[j]) cnt[i]++;
}
mn = min(mn,cnt[i]);
}
for(int i = 0; i < n; i++){
if(cnt[i] == mn) ans[i] = 1;
else ans[i] = 0;
}
return ans;
}
// int main(){
// int n; cin >> n;
// vector<int>a(n);
// for(int i = 0; i < n; i++) cin >> a[i];
// int m; cin >> m;
// vector<int>b(m),c(m),d(m);
// for(int i = 0; i < m; i++) cin >> b[i];
// for(int i = 0; i < m; i++) cin >> c[i];
// for(int i = 0; i < m; i++) cin >> d[i];
// vector<int>ans = find_reachable(a,b,c,d);
// for(int i = 0; i < n; i++) cout << ans[i] << ' ';
// }
# | 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... |