From 5874a2e5001e5490cc5d7b4bb1342cb0715f5239 Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Wed, 6 Aug 2025 21:48:43 +0900 Subject: [PATCH] =?UTF-8?q?[20250806]=20BOJ=20/=20G5=20/=20=EC=97=AC?= =?UTF-8?q?=EB=9F=AC=EB=B6=84=EC=9D=98=20=EB=8B=A4=EB=A6=AC=EA=B0=80=20?= =?UTF-8?q?=EB=90=98=EC=96=B4=20=EB=93=9C=EB=A6=AC=EA=B2=A0=EC=8A=B5?= =?UTF-8?q?=EB=8B=88=EB=8B=A4!=20/=20=EA=B9=80=EC=88=98=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\354\212\265\353\213\210\353\213\244!.md" | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 "suyeun84/202508/06 BOJ G5 \354\227\254\353\237\254\353\266\204\354\235\230 \353\213\244\353\246\254\352\260\200 \353\220\230\354\226\264 \353\223\234\353\246\254\352\262\240\354\212\265\353\213\210\353\213\244!.md" diff --git "a/suyeun84/202508/06 BOJ G5 \354\227\254\353\237\254\353\266\204\354\235\230 \353\213\244\353\246\254\352\260\200 \353\220\230\354\226\264 \353\223\234\353\246\254\352\262\240\354\212\265\353\213\210\353\213\244!.md" "b/suyeun84/202508/06 BOJ G5 \354\227\254\353\237\254\353\266\204\354\235\230 \353\213\244\353\246\254\352\260\200 \353\220\230\354\226\264 \353\223\234\353\246\254\352\262\240\354\212\265\353\213\210\353\213\244!.md" new file mode 100644 index 00000000..512f6ccb --- /dev/null +++ "b/suyeun84/202508/06 BOJ G5 \354\227\254\353\237\254\353\266\204\354\235\230 \353\213\244\353\246\254\352\260\200 \353\220\230\354\226\264 \353\223\234\353\246\254\352\262\240\354\212\265\353\213\210\353\213\244!.md" @@ -0,0 +1,44 @@ +```java +import java.io.*; +import java.util.*; + +public class boj17352 { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static StringTokenizer st; + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static int nextInt() {return Integer.parseInt(st.nextToken());} + static StringBuilder sb = new StringBuilder(); + + static int N; + static int[] parents; + public static void main(String[] args) throws Exception { + nextLine(); + N = nextInt(); + parents = new int[N+1]; + for (int i = 1; i <= N; i++) parents[i] = i; + for (int i = 0; i < N-2; i++) { + nextLine(); + int a = nextInt(); + int b = nextInt(); + union(a, b); + } + for (int i = 1; i <= N; i++) { + if (find(i) == i) sb.append(i).append(' '); + } + System.out.println(sb); + } + + static void union(int a, int b) { + int na = find(a); + int nb = find(b); + + if (na == nb) return; + parents[nb] = na; + } + + static int find(int a) { + if (parents[a] == a) return a; + return parents[a] = find(parents[a]); + } +} +```