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 <vector>
#include "bits/stdc++.h"
using namespace std;
const int MAXN = 3e5 + 10;
std::vector<int> find_reachable(std::vector<int> r, std::vector<int> u, std::vector<int> v, std::vector<int> c) {
int n = r.size();
std::vector<int> ans(n);
int m = u.size();
vector<pair<int,int> > adj[n];
for(int i=0; i<m; i++) {
adj[u[i]].push_back({v[i], c[i]});
adj[v[i]].push_back({u[i], c[i]});
}
int freq[n];
int mn = 1e9;
for(int i=0; i<n; i++) {
bool key[n];
vector<int> can[n];
bool vis[n];
for(int i=0; i<n; i++) key[i] = 0;
for(int i=0; i<n; i++) vis[i] = 0;
queue<int> q;
q.push(i);
while(q.size()) {
int f = q.front();
q.pop();
if(vis[f]) continue;
vis[f] = 1;
for(pair<int,int> x: adj[f]) {
if(vis[x.first]) continue;
if(key[x.second]) {
q.push(x.first);
}
else {
can[x.second].push_back(x.first);
}
}
if(!key[r[f]]) {
key[r[f]] = 1;
for(int x: can[r[f]]) {
q.push(x);
}
can[r[f]].clear();
}
}
int cnt = 0;
for(int i=0; i<n; i++) cnt += vis[i];
freq[i] = cnt;
mn = min(mn, freq[i]);
}
for(int i=0; i<n; i++) {
if(freq[i] == mn) {
ans[i] = 1;
}
else {
ans[i] = 0;
}
}
return ans;
}
/*
problem=keys
grader_name=grad
g++ -std=c++17 -O2 -o "${problem}" "${grader_name}.cpp" "${problem}.cpp"
"./${problem}" < input.txt
*/
# | 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... |