From a87c1826f83c321489bd9d12928422149bbb6256 Mon Sep 17 00:00:00 2001 From: oncsr Date: Sun, 24 Aug 2025 23:49:31 +0900 Subject: [PATCH] =?UTF-8?q?[20250824]=20BOJ=20/=20P5=20/=20=ED=8A=B9?= =?UTF-8?q?=EC=88=98=20=EB=8A=A5=EB=A0=A5=20/=20=EA=B6=8C=ED=98=81?= =?UTF-8?q?=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...1\354\210\230 \353\212\245\353\240\245.md" | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 "khj20006/202508/24 BOJ P5 \355\212\271\354\210\230 \353\212\245\353\240\245.md" diff --git "a/khj20006/202508/24 BOJ P5 \355\212\271\354\210\230 \353\212\245\353\240\245.md" "b/khj20006/202508/24 BOJ P5 \355\212\271\354\210\230 \353\212\245\353\240\245.md" new file mode 100644 index 00000000..431bd974 --- /dev/null +++ "b/khj20006/202508/24 BOJ P5 \355\212\271\354\210\230 \353\212\245\353\240\245.md" @@ -0,0 +1,120 @@ +```java +import java.util.*; +import java.io.*; + +class IOController { + BufferedReader br; + BufferedWriter bw; + StringTokenizer st; + + public IOController() { + br = new BufferedReader(new InputStreamReader(System.in)); + bw = new BufferedWriter(new OutputStreamWriter(System.out)); + st = new StringTokenizer(""); + } + + String nextLine() throws Exception { + String line = br.readLine(); + st = new StringTokenizer(line); + return line; + } + + String nextToken() throws Exception { + while (!st.hasMoreTokens()) nextLine(); + return st.nextToken(); + } + + int nextInt() throws Exception { + return Integer.parseInt(nextToken()); + } + + long nextLong() throws Exception { + return Long.parseLong(nextToken()); + } + + double nextDouble() throws Exception { + return Double.parseDouble(nextToken()); + } + + void close() throws Exception { + bw.flush(); + bw.close(); + } + + void write(String content) throws Exception { + bw.write(content); + } + +} + +public class Main { + + static IOController io; + + // + + static final int INF = (int)1e9 + 7; + + static int N, M, C; + static int[][] min, max; + + public static void main(String[] args) throws Exception { + + io = new IOController(); + + init(); + solve(); + + io.close(); + + } + + static void init() throws Exception { + + N = io.nextInt(); + M = io.nextInt(); + C = io.nextInt(); + min = new int[N+1][N+1]; + max = new int[N+1][N+1]; + for(int i=1;i<=N;i++) { + Arrays.fill(min[i], INF); + Arrays.fill(max[i], -INF); + } + for(int i=0;i pq = new PriorityQueue<>((a,b) -> a[0]-b[0]); + pq.offer(new int[]{0,1,0}); + while(!pq.isEmpty()) { + int[] cur = pq.poll(); + int d = cur[0], n = cur[1], t = cur[2]; + if(d > dist[n]) continue; + for(int i=1;i<=N;i++) if(min[n][i] != INF) { + if(t d - max[n][i]) { + dist[i] = d - max[n][i]; + pq.offer(new int[]{dist[i], i, t+1}); + } + if(dist[i] > d + min[n][i]) { + dist[i] = d + min[n][i]; + pq.offer(new int[]{dist[i], i, t}); + } + } + } + io.write(dist[N] + "\n"); + + } + +} +```