diff --git "a/\354\235\264\354\275\224\355\205\214/10 \352\267\270\353\236\230\355\224\204 \354\235\264\353\241\240/\355\214\200_\352\262\260\354\204\261/\354\244\200\355\230\270.java" "b/\354\235\264\354\275\224\355\205\214/10 \352\267\270\353\236\230\355\224\204 \354\235\264\353\241\240/\355\214\200_\352\262\260\354\204\261/\354\244\200\355\230\270.java" new file mode 100644 index 0000000..26e80ad --- /dev/null +++ "b/\354\235\264\354\275\224\355\205\214/10 \352\267\270\353\236\230\355\224\204 \354\235\264\353\241\240/\355\214\200_\352\262\260\354\204\261/\354\244\200\355\230\270.java" @@ -0,0 +1,49 @@ +import java.util.*; + +public class 준호 { + public static int N ,M; + public static int[] parent = new int[100001]; + + public static int findParent(int x) { + if(parent[x] == x) return x; + return parent[x] = findParent(parent[x]); + } + + public static void unionParent(int a, int b) { + a = findParent(a); + b = findParent(b); + if (a > b) { + parent[a] = b; + } else { + parent[b] = a; + } + } + + public static void main(String[] args) { + + Scanner scanner = new Scanner(System.in); + N = scanner.nextInt(); + M = scanner.nextInt(); + + for (int i = 0; i <= N; i++) { + parent[i] = i; + } + + StringBuilder result = new StringBuilder(); + for (int i = 0; i < M; i++) { + int a = scanner.nextInt(); + int b = scanner.nextInt(); + int c = scanner.nextInt(); + if (a == 1) { + if (findParent(b) == findParent(c)) { + result.append("YES "); + } else { + result.append("NO "); + } + } else { + unionParent(b, c); + } + } + System.out.println(result); + } +}