From d180542c67305edf7e452ca7652e193410d7ca7a Mon Sep 17 00:00:00 2001 From: zinnnn37 Date: Thu, 25 Dec 2025 22:55:43 +0900 Subject: [PATCH] =?UTF-8?q?[20251225]=20BOJ=20/=20G3=20/=20=EC=A4=91?= =?UTF-8?q?=EB=9F=89=EC=A0=9C=ED=95=9C=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 --- ...21\353\237\211\354\240\234\355\225\234.md" | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 "zinnnn37/202512/25 BOJ G3 \354\244\221\353\237\211\354\240\234\355\225\234.md" diff --git "a/zinnnn37/202512/25 BOJ G3 \354\244\221\353\237\211\354\240\234\355\225\234.md" "b/zinnnn37/202512/25 BOJ G3 \354\244\221\353\237\211\354\240\234\355\225\234.md" new file mode 100644 index 00000000..c8429852 --- /dev/null +++ "b/zinnnn37/202512/25 BOJ G3 \354\244\221\353\237\211\354\240\234\355\225\234.md" @@ -0,0 +1,98 @@ +```java +import java.io.*; +import java.util.*; + +public class BJ_1939_중량제한 { + + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static StringTokenizer st; + + private static int N, M, start, end; + private static int[] maxWeight; + private static List[] graph; + private static Queue pq; + + private static class Node implements Comparable { + int to; + int weight; + + public Node(int to, int weight) { + this.to = to; + this.weight = weight; + } + + @Override + public int compareTo(Node o) { + return Integer.compare(o.weight, this.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()); + + graph = new List[N + 1]; + for (int i = 1; i <= N; i++) { + graph[i] = new ArrayList<>(); + } + + for (int i = 1; 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()); + + graph[a].add(new Node(b, c)); + graph[b].add(new Node(a, c)); + } + + maxWeight = new int[N + 1]; + + st = new StringTokenizer(br.readLine()); + start = Integer.parseInt(st.nextToken()); + end = Integer.parseInt(st.nextToken()); + maxWeight[start] = Integer.MAX_VALUE; + + pq = new PriorityQueue<>(); + } + + private static void sol() throws IOException { + pq.offer(new Node(start, Integer.MAX_VALUE)); + + while (!pq.isEmpty()) { + Node cur = pq.poll(); + + if (cur.to == end) { + bw.write(String.valueOf(cur.weight)); + bw.flush(); + bw.close(); + br.close(); + return; + } + + if (cur.weight < maxWeight[cur.to]) { + continue; + } + + for (Node next : graph[cur.to]) { + int newWeight = Math.min(cur.weight, next.weight); + + if (newWeight > maxWeight[next.to]) { + maxWeight[next.to] = newWeight; + pq.offer(new Node(next.to, newWeight)); + } + } + } + } + +} +``` \ No newline at end of file