From 0888aeeb8540031eea663a90eb11978a2f9a4fb9 Mon Sep 17 00:00:00 2001 From: LiiNi-coder <97495437+LiiNi-coder@users.noreply.github.com> Date: Fri, 1 Aug 2025 23:52:01 +0900 Subject: [PATCH] =?UTF-8?q?[20250801]=20BOJ=20/=20G5=20/=20=EC=A7=91?= =?UTF-8?q?=ED=95=A9=EC=9D=98=20=ED=91=9C=ED=98=84=20/=20=EC=9D=B4?= =?UTF-8?q?=EC=9D=B8=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...1\354\235\230 \355\221\234\355\230\204.md" | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 "LiiNi-coder/202508/01 BOJ \354\247\221\355\225\251\354\235\230 \355\221\234\355\230\204.md" 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