From 5a47713be259060d790667822c3c384bd48f1337 Mon Sep 17 00:00:00 2001 From: LiiNi-coder <97495437+LiiNi-coder@users.noreply.github.com> Date: Sun, 7 Dec 2025 23:56:10 +0900 Subject: [PATCH] =?UTF-8?q?[20251207]=20BOJ=20/=20G5=20/=20=ED=98=B8?= =?UTF-8?q?=EC=84=9D=EC=9D=B4=20=EB=91=90=EB=A7=88=EB=A6=AC=20=EC=B9=98?= =?UTF-8?q?=ED=82=A8=20/=20=EC=9D=B4=EC=9D=B8=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\210\353\246\254 \354\271\230\355\202\250" | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 "LiiNi-coder/202512/07 BOJ \355\230\270\354\204\235\354\235\264 \353\221\220\353\247\210\353\246\254 \354\271\230\355\202\250" diff --git "a/LiiNi-coder/202512/07 BOJ \355\230\270\354\204\235\354\235\264 \353\221\220\353\247\210\353\246\254 \354\271\230\355\202\250" "b/LiiNi-coder/202512/07 BOJ \355\230\270\354\204\235\354\235\264 \353\221\220\353\247\210\353\246\254 \354\271\230\355\202\250" new file mode 100644 index 00000000..5ff12969 --- /dev/null +++ "b/LiiNi-coder/202512/07 BOJ \355\230\270\354\204\235\354\235\264 \353\221\220\353\247\210\353\246\254 \354\271\230\355\202\250" @@ -0,0 +1,58 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + static final int INF = 100_000_000; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + int N = Integer.parseInt(st.nextToken()); + int M = Integer.parseInt(st.nextToken()); + int[][] dist = new int[N + 1][N + 1]; + for(int i = 1; i <= N; i++){ + for(int j = 1; j <= N; j++){ + if(i == j) dist[i][j] = 0; + else dist[i][j] = INF; + } + } + for(int i = 0; i < M; i++){ + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + dist[a][b] = 1; + dist[b][a] = 1; + } + //플로이드워셜 + for(int k = 1; k <= N; k++){ + for(int i = 1; i <= N; i++){ + for(int j = 1; j <= N; j++){ + if(dist[i][j] > dist[i][k] + dist[k][j]){ + dist[i][j] = dist[i][k] + dist[k][j]; + } + } + } + } + int bestI = 0; + int bestJ = 0; + int bestSum = INF; + for(int i = 1; i <= N; i++){ + for(int j = i + 1; j <= N; j++){ + int sum = 0; + for(int k = 1; k <= N; k++){ + int d = Math.min(dist[k][i], dist[k][j]); + sum += d*2; + } + if(sum < bestSum){ + bestSum = sum; + bestI = i; + bestJ = j; + } + } + } + System.out.println(bestI + " " + bestJ + " " + bestSum); + } +} + +```