From fe1055e697625bd44c46d9995dfcbead9e59a79b Mon Sep 17 00:00:00 2001 From: zinnnn37 Date: Mon, 29 Dec 2025 23:38:36 +0900 Subject: [PATCH] =?UTF-8?q?[20251229]=20BOJ=20/=20G3=20/=20=ED=83=9D?= =?UTF-8?q?=EB=B0=B0=20/=20=EA=B9=80=EB=AF=BC=EC=A7=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../29 BOJ G3 \355\203\235\353\260\260.md" | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 "zinnnn37/202512/29 BOJ G3 \355\203\235\353\260\260.md" diff --git "a/zinnnn37/202512/29 BOJ G3 \355\203\235\353\260\260.md" "b/zinnnn37/202512/29 BOJ G3 \355\203\235\353\260\260.md" new file mode 100644 index 00000000..e8f3a7db --- /dev/null +++ "b/zinnnn37/202512/29 BOJ G3 \355\203\235\353\260\260.md" @@ -0,0 +1,85 @@ +```java +import java.io.*; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class BJ_1719_택배 { + + private static final int INF = 987654321; + + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static final StringBuilder sb = new StringBuilder(); + private static StringTokenizer st; + + private static int N, M; + private static int[][] dist, route; + + private static class Node { + int to; + int weight; + + Node(int to, int weight) { + this.to = to; + this.weight = weight; + } + + } + + public static void main(String[] args) throws IOException { + init(); + sol(); + } + + private static void init() throws IOException { + st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + + dist = new int[N + 1][N + 1]; + route = new int[N + 1][N + 1]; + for (int i = 1; i <= N; i++) { + Arrays.fill(dist[i], INF); + dist[i][i] = 0; + } + + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine()); + + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + int c = Integer.parseInt(st.nextToken()); + + dist[a][b] = dist[b][a] = Math.min(dist[a][b], c); + route[a][b] = b; + route[b][a] = a; + } + } + + private static void sol() throws IOException { + 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]; + route[i][j] = route[i][k]; + } + } + } + } + + for (int i = 1; i <= N; i++) { + for (int j = 1; j <= N; j++) { + sb.append(i == j ? "-" : route[i][j]); + if (j < N) sb.append(" "); + } + sb.append("\n"); + } + bw.write(sb.toString()); + bw.flush(); + bw.close(); + br.close(); + } + +} +```