diff --git "a/LiiNi-coder/202508/01 BOJ \354\247\221\355\225\251\354\235\230 \355\221\234\355\230\204.md" "b/LiiNi-coder/202508/01 BOJ \354\247\221\355\225\251\354\235\230 \355\221\234\355\230\204.md" new file mode 100644 index 00000000..0e84e372 --- /dev/null +++ "b/LiiNi-coder/202508/01 BOJ \354\247\221\355\225\251\354\235\230 \355\221\234\355\230\204.md" @@ -0,0 +1,75 @@ +```java +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Iterator; +import java.util.StringTokenizer; + +public class Main { + private static class WeightedUF{ + int[] ids; + int[] size; + public WeightedUF(int v) { + ids = new int[v]; + size = new int[v]; + for (int i = 0; i < ids.length; i++) { + ids[i] = i; + size[i] = 1; + } + } + public int root(int a) { + while(a != ids[a]) + a = ids[a]; + return a; + } + public void union(int a, int b) { + int g, l; + if(size[a] >= size[b]) { + g = a; + l = b; + }else { + l = a; + g = b; + } + // b가 더 깊이가 짧음 + ids[root(b)] = root(a); + } + public boolean connected(int a, int b) { + return root(a) == root(b); + } + } + private static BufferedReader br; + private static Main.WeightedUF uf; + private static int m; + private static int n; + public static void main(String[] args) throws IOException { + br = new BufferedReader(new InputStreamReader(System.in)); + StringBuilder sb = new StringBuilder(); + String[] temp = br.readLine().split(" "); + n = Integer.parseInt(temp[0])+1; + m = Integer.parseInt(temp[1]); + uf = new WeightedUF(n); + + for(int i = 0; i