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;
typedef pair<int,int> ii;
typedef vector<int> vi;
const int MAX=1e9;
const int MAX_N=1e5;
vector<vi> G;
bool vis[MAX_N];
vector<vi> ll;
int pa[MAX_N],tam[MAX_N];
void init(int n){
for(int i=0;i<n;i++){
pa[i]=i; tam[i]=1;
}
}
int findset(int i){
if(pa[i]==i) return i;
return pa[i]=findset(pa[i]);
}
bool issameset(int i,int j){
return findset(i)==findset(j);
}
void unionset(int i,int j){
if(!issameset(i,j)){
int u=findset(i),v=findset(j);
if(tam[u]>tam[v]){
pa[v]=u; tam[u]+=tam[v];
}
else{
pa[u]=v; tam[v]+=tam[u];
}
}
}
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(); int m=u.size();
ll.resize(n+1);
for(int i=0;i<m;i++){
ll[c[i]].push_back(i);
}
vector<int> ans(n,0);
int mi=MAX;
for(int i=0;i<n;i++){
init(n);
memset(vis,0,sizeof vis);
queue<int> q;
q.push(r[i]);
vis[r[i]]=1;
while(!q.empty()){
int x=q.front();
q.pop();
for(int j=0;j<ll[x].size();j++){
int a=u[ll[x][j]],b=v[ll[x][j]];
unionset(a,b);
}
for(int j=0;j<n;j++){
if(!vis[r[j]] && issameset(i,j)){
vis[r[j]]=1;
q.push(r[j]);
}
}
}
if(mi>tam[findset(i)]){
for(int j=0;j<n;j++) ans[j]=0;
mi=tam[findset(i)];
}
if(mi==tam[findset(i)]){
ans[i]=1;
}
//cout<<tam[findset(i)]<<endl;
}
return ans;
}
Compilation message (stderr)
keys.cpp: In function 'std::vector<int> find_reachable(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
keys.cpp:52:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for(int j=0;j<ll[x].size();j++){
| ~^~~~~~~~~~~~~
# | 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... |