From d43e11e465690c03be11582c5db46535b582ddef Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Wed, 26 Feb 2025 16:51:33 +0900 Subject: [PATCH] =?UTF-8?q?[20250226]=20BOJ=20/=20=EA=B3=A8=EB=93=9C4=20/?= =?UTF-8?q?=20=ED=94=8C=EB=A1=9C=EC=9D=B4=EB=93=9C=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 --- ...14\353\241\234\354\235\264\353\223\234.md" | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 "suyeun84/202502/26 BOJ G4 \355\224\214\353\241\234\354\235\264\353\223\234.md" diff --git "a/suyeun84/202502/26 BOJ G4 \355\224\214\353\241\234\354\235\264\353\223\234.md" "b/suyeun84/202502/26 BOJ G4 \355\224\214\353\241\234\354\235\264\353\223\234.md" new file mode 100644 index 00000000..6eeef6a4 --- /dev/null +++ "b/suyeun84/202502/26 BOJ G4 \355\224\214\353\241\234\354\235\264\353\223\234.md" @@ -0,0 +1,72 @@ +```java +import java.util.*; +import java.io.*; + +public class boj11404 { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static int nextInt() {return Integer.parseInt(st.nextToken());} + static void end() throws Exception { + bw.flush(); + bw.close(); + br.close(); + } + public static void main(String[] args) throws Exception { + nextLine(); + int N = nextInt(); //도시 개수 + nextLine(); + int M = nextInt(); //버스 개수 + int[][] answer = new int[N+1][N+1]; + for (int i = 1; i < N+1; i++) { + Arrays.fill(answer[i], Integer.MAX_VALUE); + } + + for (int i = 0; i < M; i++) { + nextLine(); + int a = nextInt(); + int b = nextInt(); + int c = nextInt(); + answer[a][b] = Math.min(answer[a][b], c); + } + + for (int k = 1; k < N+1; k++) { + for (int i = 1; i < N+1; i++) { + for (int j = 1; j < N+1; j++) { + if (i == j) { + answer[i][j] = 0; + continue; + } + if (answer[i][k] == Integer.MAX_VALUE || answer[k][j] == Integer.MAX_VALUE) continue; + answer[i][j] = Math.min(answer[i][j], answer[i][k]+answer[k][j]); + } + } + } + for (int i = 1; i < N+1; i++) { + for (int j = 1; j < N+1; j++) { + if (answer[i][j] == Integer.MAX_VALUE) { + bw.write("0 "); + continue; + } + bw.write(answer[i][j]+" "); + } + bw.write("\n"); + bw.flush(); + } + end(); + } + + static class Node { + int a; + int b; + int c; + public Node(int a, int b, int c) { + this.a = a; + this.b = b; + this.c = c; + } + } +} + +```