diff --git "a/JHLEE325/202507/12 BOJ G5 \354\265\234\354\206\214\353\271\204\354\232\251\352\265\254\355\225\230\352\270\260" "b/JHLEE325/202507/12 BOJ G5 \354\265\234\354\206\214\353\271\204\354\232\251\352\265\254\355\225\230\352\270\260" new file mode 100644 index 00000000..7ddcc249 --- /dev/null +++ "b/JHLEE325/202507/12 BOJ G5 \354\265\234\354\206\214\353\271\204\354\232\251\352\265\254\355\225\230\352\270\260" @@ -0,0 +1,68 @@ +```java +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.*; + +public class Main { + static class Node implements Comparable { + int idx, cost; + + Node(int idx, int cost) { + this.idx = idx; + this.cost = cost; + } + + @Override + public int compareTo(Node o) { + return Integer.compare(this.cost, o.cost); + } + } + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + StringBuilder sb = new StringBuilder(); + + int n = Integer.parseInt(br.readLine()); + int m = Integer.parseInt(br.readLine()); + + List> graph = new ArrayList<>(); + for (int i = 0; i <= n; i++) + graph.add(new ArrayList<>()); + + for (int i = 0; i < m; i++) { + st = new StringTokenizer(br.readLine()); + int from = Integer.parseInt(st.nextToken()); + int to = Integer.parseInt(st.nextToken()); + int c = Integer.parseInt(st.nextToken()); + graph.get(from).add(new Node(to, c)); + } + + st = new StringTokenizer(br.readLine()); + int start = Integer.parseInt(st.nextToken()); + int end = Integer.parseInt(st.nextToken()); + + int[] dist = new int[n + 1]; + Arrays.fill(dist, Integer.MAX_VALUE); + dist[start] = 0; + + PriorityQueue pq = new PriorityQueue<>(); + pq.offer(new Node(start, 0)); + + while (!pq.isEmpty()) { + Node cur = pq.poll(); + int now = cur.idx; + + if (cur.cost > dist[now]) continue; + + for (Node next : graph.get(now)) { + if (dist[next.idx] > dist[now] + next.cost) { + dist[next.idx] = dist[now] + next.cost; + pq.offer(new Node(next.idx, dist[next.idx])); + } + } + } + System.out.println(dist[end]); + } +} +```