이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "friend.h"
using namespace std;
/*******************/
#define pi pair<int,int>
#define ll long long
#define f first
#define s second
#define pb push_back
struct UnionFind{
vector<int> parent, height, sz;
void init(int n){
height.clear();
height.assign(n, 0);
parent.clear();
parent.assign(n, 0);
sz.clear();
sz.assign(n, 1);
for(int i=0; i<n ;i++){
parent[i] = i;
}
}
int root(int n){
if(parent[n]!= n)
parent[n] = root(parent[n]);
return parent[n];
}
bool same(int n1, int n2){
return root(n1) == root(n2);
}
void join(int n1, int n2){
int r1 = root(n1);
int r2 = root(n2);
if(height[r1] > height[r2]){
parent[r2] = r1;
height[r1] = max(height[r1], height[r2] + 1);
sz[r1] += sz[r2];
//cout << sz[r1]<<"; "<<sz[r2]<<endl;
}else{
parent[r1] = r2;
height[r2] = max(height[r2], height[r1] + 1);
sz[r2]+=sz[r1];
//cout << sz[r1]<<";; "<<sz[r2]<<endl;
}
}
};
int findSample(int n,int confidence[],int host[],int protocol[]){
UnionFind uf;
uf.init(n);
for(int i =1; i<n; i++){
if(protocol[i] == 1){
uf.join(i, host[i]);
//cout << i <<", "<<host[i]<<endl;
}
}
set<int> roots;
for(int i =0;i < n; i++){
roots.insert(uf.root(i));
}
int ans =0;
for(int rt : roots){
//cout <<rt<<": "<< uf.sz[rt]<<endl;
ans = max(ans, uf.sz[rt]);
}
return max(ans, (int)roots.size());
}
/*******************/
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |