From 18c3ae6e7c7d23b1ac0439ca74bd3088216bfe63 Mon Sep 17 00:00:00 2001 From: zinnnn37 Date: Sat, 27 Dec 2025 22:36:05 +0900 Subject: [PATCH] =?UTF-8?q?[20251227]=20BOJ=20/=20G4=20/=20=ED=95=B4?= =?UTF-8?q?=ED=82=B9=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 --- .../27 BOJ G4 \355\225\264\355\202\271.md" | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 "zinnnn37/202512/27 BOJ G4 \355\225\264\355\202\271.md" diff --git "a/zinnnn37/202512/27 BOJ G4 \355\225\264\355\202\271.md" "b/zinnnn37/202512/27 BOJ G4 \355\225\264\355\202\271.md" new file mode 100644 index 00000000..73dd58c3 --- /dev/null +++ "b/zinnnn37/202512/27 BOJ G4 \355\225\264\355\202\271.md" @@ -0,0 +1,104 @@ +```java +import java.io.*; +import java.util.*; + +public class BJ_10282_해킹 { + + 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, D, C; + private static int[] dist; + private static Queue pq; + private static List[] graph; + + private static class Node implements Comparable { + int to; + int weight; + + Node(int to, int weight) { + this.to = to; + this.weight = weight; + } + + @Override + public int compareTo(Node o) { + return Integer.compare(this.weight, o.weight); + } + + } + + public static void main(String[] args) throws IOException { + int T = Integer.parseInt(br.readLine()); + + while (T-- > 0) { + init(); + sol(); + } + bw.write(sb.toString()); + bw.flush(); + bw.close(); + br.close(); + } + + private static void init() throws IOException { + st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + D = Integer.parseInt(st.nextToken()); + C = Integer.parseInt(st.nextToken()); + + graph = new List[N + 1]; + for (int i = 1; i <= N; i++) { + graph[i] = new ArrayList<>(); + } + + dist = new int[N + 1]; + Arrays.fill(dist, Integer.MAX_VALUE); + + pq = new PriorityQueue<>(); + for (int i = 0; i < D; i++) { + st = new StringTokenizer(br.readLine()); + + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + int s = Integer.parseInt(st.nextToken()); + + graph[b].add(new Node(a, s)); + } + + } + + private static void sol() throws IOException { + pq.offer(new Node(C, 0)); + dist[C] = 0; + + while (!pq.isEmpty()) { + Node cur = pq.poll(); + + if (cur.weight > dist[cur.to]) continue; + + for (Node next : graph[cur.to]) { + int nextWeight = dist[cur.to] + next.weight; + + if (dist[next.to] > nextWeight) { + dist[next.to] = nextWeight; + pq.offer(new Node(next.to, nextWeight)); + } + } + } + + int cnt = 0; + int max = 0; + for (int i = 1; i <= N; i++) { + if (dist[i] == Integer.MAX_VALUE) continue; + + cnt++; + max = Math.max(max, dist[i]); + } + sb.append(cnt).append(" ").append(max).append("\n"); + } + +} +``` \ No newline at end of file