Skip to content

Instantly share code, notes, and snippets.

@godtaehee
Created May 2, 2019 15:21
Show Gist options
  • Save godtaehee/1e774d72c3aaee696170b715166ab5ac to your computer and use it in GitHub Desktop.
Save godtaehee/1e774d72c3aaee696170b715166ab5ac to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
int counting = 0;
class Node{
public:
int value;
Node* ptr;
Node(int value) : value(value) {
ptr = this;
}
};
Node* makeSet(int value){
Node* newNode = new Node(value);
return newNode;
}
Node* FindSet(Node* x){
if(x -> value == x->ptr->value)
return x;
else
return FindSet(x->ptr);
}
void Union(Node* x, Node* y){
FindSet(y)->ptr = FindSet(x);
}
int main(){
int n;
int m;
Node* root;
int x, y;
cin >> n >> m;
Node* arr[n+1];
Node* carr[n+1];
int gk[n+1];
for(int i = 1; i <= n; i++){
arr[i] = makeSet(i);
}
for(int i = 0; i < m; i++){
cin >> x >> y;
Union(arr[x], arr[y]);
}
for(int i = 1; i <=n; i++){
gk[i] = 0;
carr[i] = FindSet(arr[i]);
}
for(int i = 1; i <=n; i++){
gk[carr[i] -> value]++;
}
int max = gk[1];
for(int i = 2; i <=n; i++){
if(max < gk[i])
max = gk[i];
}
cout << max;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment