이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define vi vector<int>
using namespace std;
struct uNumber{
int c;
uNumber(){c = 0;}
int operator ()() {return c++;}
} UniqueN;
struct UF{
private:
public:
vi ranki,p,sz;
UF(int n){
ranki.assign(n, 0);
p.assign(n, 0);
sz.assign(n,0);
generate(p.begin(),p.end(),UniqueN);
}
int findset(int i){ return (p[i] == i) ? i : findset(p[i]);}
bool issameset(int i, int j) {return findset(i) == findset(j);}
void unionset(int i, int j){
if(!issameset(i,j)){
int x = findset(i), y = findset(j);
if(ranki[x] > ranki[y]){
p[y] = x;
sz[x] += sz[y]+1;
sz[y] = sz[x];
}else{
if(ranki[x] == ranki[y]) ranki[y]++;
p[x] = y;
sz[y] += sz[x]+1;
sz[x] = sz[y];
}
}
}
};
vector<int> find_reachable(vector<int> r, vector<int> u, vector<int> v, vector<int> c) {
int n = (int) r.size();
int m = (int) c.size();
vector<int> ans(n, 0);
bool flag = false;
for(int i = 0; i < n; i++){
if(r[i] != 0){
ans[i] = 1;
flag = true;
}
}
if(!flag){
ans.assign(n,1);
}
vector<vector<int>> g(n,vector<int>());
UF unionfind(n);
for(int i = 0; i < m; i++){
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
unionfind.unionset(u[i],v[i]);
}
int mini = *min_element(unionfind.sz.begin(),unionfind.sz.end());
for(int i = 0; i < n; i++){
if(unionfind.sz[i] == mini){
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... |