알고리즘/union and find1 여러가지 종교 더블릿 12345678910111213141516171819202122232425262728293031323334353637383940414243444546#include #include using namespace std; int root[200000] = { 0 }; int find(int x) { if (root[x] == x) return x; else return root[x] = find(root[x]);} void unify(int a, int b) { a = find(a); b = find(b); if (a > b) swap(a, b); root[b] = a;} int main() { int n, m; scanf("%d %d", &n, &m); for (int i = 1; i 2019. 2. 27. 이전 1 다음