From b934a4087d4013af69c90be110d2081045b36ff3 Mon Sep 17 00:00:00 2001 From: LiiNi-coder <97495437+LiiNi-coder@users.noreply.github.com> Date: Fri, 17 Oct 2025 23:57:30 +0900 Subject: [PATCH] =?UTF-8?q?[20251017]=20BOJ=20/=20G4=20/=20=EA=B0=80?= =?UTF-8?q?=EC=9E=A5=20=EB=A8=BC=20=EA=B3=B3=20/=20=EC=9D=B4=EC=9D=B8?= =?UTF-8?q?=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\236\245 \353\250\274 \352\263\263.md" | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 "LiiNi-coder/202510/17 BOJ \352\260\200\354\236\245 \353\250\274 \352\263\263.md" diff --git "a/LiiNi-coder/202510/17 BOJ \352\260\200\354\236\245 \353\250\274 \352\263\263.md" "b/LiiNi-coder/202510/17 BOJ \352\260\200\354\236\245 \353\250\274 \352\263\263.md" new file mode 100644 index 00000000..62c7d64c --- /dev/null +++ "b/LiiNi-coder/202510/17 BOJ \352\260\200\354\236\245 \353\250\274 \352\263\263.md" @@ -0,0 +1,93 @@ +```java +import java.util.*; +import java.io.*; + +class Main { + + static class Node implements Comparable { + int to, weight; + + Node(int to, int weight) { + this.to = to; + this.weight = weight; + } + + @Override + public int compareTo(Node o){ + return this.weight - o.weight; + } + } + + static int N, M; + static List[] Graph; + static int[] Friends = new int[3]; + static final int INF = Integer.MAX_VALUE; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + N = Integer.parseInt(br.readLine()); + st = new StringTokenizer(br.readLine()); + for(int i = 0; i < 3; i++) + Friends[i] = Integer.parseInt(st.nextToken()); + + M = Integer.parseInt(br.readLine()); + Graph = new ArrayList[N + 1]; + for(int i = 1; i <= N; i++) + Graph[i] = new ArrayList<>(); + + for (int i = 0; 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)); + } + + int[][] dist = new int[3][N + 1]; + for(int i = 0; i < 3; i++){ + dist[i] = dijkstra(Friends[i]); + } + int answer = 0; + int maxMinDist = -1; + + for(int i = 1; i <= N; i++){ + int minDist = Math.min(dist[0][i], Math.min(dist[1][i], dist[2][i])); + if (minDist > maxMinDist) { + maxMinDist = minDist; + answer = i; + } + } + + + System.out.println(answer); + br.close(); + } + + private static int[] dijkstra(int start) { + int[] dist = new int[N + 1]; + Arrays.fill(dist, INF); + dist[start] = 0; + + PriorityQueue pq = new PriorityQueue<>(); + pq.offer(new Node(start, 0)); + while(!pq.isEmpty()){ + Node cur = pq.poll(); + if(cur.weight > dist[cur.to]) + continue; + + for(Node next : Graph[cur.to]){ + int cost = cur.weight + next.weight; + if(cost < dist[next.to]){ + dist[next.to] = cost; + pq.offer(new Node(next.to, cost)); + } + } + } + return dist; + } +} + +```