From f538bd181b1d758d97c7a553d4f5f91031262ae7 Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Thu, 7 Aug 2025 23:55:08 +0900 Subject: [PATCH] =?UTF-8?q?[20250807]=20BOJ=20/=20G5=20/=20=EC=86=8C?= =?UTF-8?q?=EC=85=9C=20=EB=84=A4=ED=8A=B8=EC=9B=8C=ED=82=B9=20=EC=96=B4?= =?UTF-8?q?=ED=94=8C=EB=A6=AC=EC=BC=80=EC=9D=B4=EC=85=98=20/=20=EA=B9=80?= =?UTF-8?q?=EC=88=98=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...54\354\274\200\354\235\264\354\205\230.md" | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 "suyeun84/202508/07 BOJ \354\206\214\354\205\234 \353\204\244\355\212\270\354\233\214\355\202\271 \354\226\264\355\224\214\353\246\254\354\274\200\354\235\264\354\205\230.md" diff --git "a/suyeun84/202508/07 BOJ \354\206\214\354\205\234 \353\204\244\355\212\270\354\233\214\355\202\271 \354\226\264\355\224\214\353\246\254\354\274\200\354\235\264\354\205\230.md" "b/suyeun84/202508/07 BOJ \354\206\214\354\205\234 \353\204\244\355\212\270\354\233\214\355\202\271 \354\226\264\355\224\214\353\246\254\354\274\200\354\235\264\354\205\230.md" new file mode 100644 index 00000000..6161e664 --- /dev/null +++ "b/suyeun84/202508/07 BOJ \354\206\214\354\205\234 \353\204\244\355\212\270\354\233\214\355\202\271 \354\226\264\355\224\214\353\246\254\354\274\200\354\235\264\354\205\230.md" @@ -0,0 +1,77 @@ +```java +import java.io.*; +import java.util.*; + +public class boj7511 { + 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, m; + static int[] parents; + public static void main(String[] args) throws Exception { + nextLine(); + int t = nextInt(); + for(int a = 1 ; a <= t ; a++){ + nextLine(); + n = nextInt(); + + for(int i = 0 ; i < n ; i++) { + parents[i] = i; + } + + nextLine(); + m = nextInt(); + + for(int i = 0 ; i < m ; i++) { + nextLine(); + int v1 = nextInt(); + int v2 = nextInt(); + + if(find(v1) != find(v2)) { + union(v1,v2); + } + } + + nextLine(); + int k = nextInt(); + + sb.append("Scenario "+a+":\n"); + + for(int i = 0 ; i < k ; i++){ + nextLine(); + int v1 = nextInt(); + int v2 = nextInt(); + + if(find(v1) == find(v2)) { + sb.append("1\n"); + }else{ + sb.append("0\n"); + } + }sb.append("\n"); + } + + System.out.println(sb); + br.close(); + } + + static int find(int x) { + if(x == parents[x]) + return parents[x]; + + return parents[x] = find(parents[x]); + } + + static void union(int x,int y) { + x = find(x); + y = find(y); + + if(x < y) + parents[y] = x; + else + parents[x] = y; + } +} +```