From 7432d6860bd7579fc695924ffcbf7e8f2077633b Mon Sep 17 00:00:00 2001 From: JHLEE325 <82587652+JHLEE325@users.noreply.github.com> Date: Wed, 10 Sep 2025 08:16:54 +0900 Subject: [PATCH] =?UTF-8?q?[20250910]=20BOJ=20/=20G3=20/=20=ED=83=9D?= =?UTF-8?q?=EB=B0=B0=20/=20=EC=9D=B4=EC=A4=80=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../10 BOJ G3 \355\203\235\353\260\260.md" | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 "JHLEE325/202509/10 BOJ G3 \355\203\235\353\260\260.md" diff --git "a/JHLEE325/202509/10 BOJ G3 \355\203\235\353\260\260.md" "b/JHLEE325/202509/10 BOJ G3 \355\203\235\353\260\260.md" new file mode 100644 index 00000000..ba33f6a0 --- /dev/null +++ "b/JHLEE325/202509/10 BOJ G3 \355\203\235\353\260\260.md" @@ -0,0 +1,62 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + static final int INF = 987654321; + + 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][n]; + int[][] next = new int[n][n]; + + for (int i = 0; i < n; i++) { + Arrays.fill(dist[i], INF); + dist[i][i] = 0; + Arrays.fill(next[i], -1); + } + + for (int i = 0; i < m; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()) - 1; + int b = Integer.parseInt(st.nextToken()) - 1; + int c = Integer.parseInt(st.nextToken()); + + if (c < dist[a][b]) { + dist[a][b] = c; + dist[b][a] = c; + next[a][b] = b; + next[b][a] = a; + } + } + + for (int k = 0; k < n; k++) { + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (dist[i][j] > dist[i][k] + dist[k][j]) { + dist[i][j] = dist[i][k] + dist[k][j]; + next[i][j] = next[i][k]; + } + } + } + } + + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (i == j) sb.append("- "); + else sb.append(next[i][j] + 1).append(" "); + } + sb.append("\n"); + } + + System.out.print(sb); + } +} + +```