이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <vector>
#include <bits/stdc++.h>
using namespace std;
int n;
vector<pair<int,int>> g[300001];
int cmp[300001];
int tal[300001];
void flood(int x,int c){
cmp[x]=c;
tal[cmp[x]]++;
for(auto i:g[x])if(!cmp[i.first])flood(i.first,c);
}
std::vector<int> find_reachable(std::vector<int> r, std::vector<int> u, std::vector<int> v, std::vector<int> c) {
n=r.size();
for(int i=0;i<n;i++){g[u[i]].push_back({v[i],c[i]});g[v[i]].push_back({u[i],c[i]});}
vector<int> ans(n);
bool f=0;
for(int i=0;i<n;i++){
ans[i]=0;
if(r[i]!=0){f=1;ans[i]=1;}
}
if(f==0){
int cc=1;
for(int i=0;i<n;i++){if(cmp[i])continue;flood(i,cc);cc++;}
int talm=1e9;
for(int i=0;i<n;i++)if(tal[i]>0)talm=min(tal[i],talm);
for(int i=0;i<n;i++)if(tal[cmp[i]]==talm)ans[i]=1;
}
return ans;
}
# | 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... |