Created
May 2, 2019 15:21
-
-
Save godtaehee/1e774d72c3aaee696170b715166ab5ac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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