From 95a1725d231b00ac6080b2a0a41022cf04127b18 Mon Sep 17 00:00:00 2001 From: LiiNi-coder <97495437+LiiNi-coder@users.noreply.github.com> Date: Tue, 23 Dec 2025 23:55:15 +0900 Subject: [PATCH] =?UTF-8?q?[20251223]=20BOJ=20/=20G4=20/=20=ED=96=89?= =?UTF-8?q?=EC=84=B1=20=EC=97=B0=EA=B2=B0=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 --- ...1\354\204\261 \354\227\260\352\262\260.md" | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 "LiiNi-coder/202512/23 BOJ \355\226\211\354\204\261 \354\227\260\352\262\260.md" diff --git "a/LiiNi-coder/202512/23 BOJ \355\226\211\354\204\261 \354\227\260\352\262\260.md" "b/LiiNi-coder/202512/23 BOJ \355\226\211\354\204\261 \354\227\260\352\262\260.md" new file mode 100644 index 00000000..fec17eb4 --- /dev/null +++ "b/LiiNi-coder/202512/23 BOJ \355\226\211\354\204\261 \354\227\260\352\262\260.md" @@ -0,0 +1,46 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int N = Integer.parseInt(br.readLine()); + int[][] cost = new int[N][N]; + for(int i = 0; i < N; i++){ + StringTokenizer st = new StringTokenizer(br.readLine()); + for(int j = 0; j < N; j++){ + cost[i][j] = Integer.parseInt(st.nextToken()); + } + } + boolean[] visited = new boolean[N]; + PriorityQueue pq = new PriorityQueue<>( + (a, b) -> a[1] - b[1] + ); + pq.offer(new int[]{0, 0}); + + long answer = 0; + int count = 0; + while(!pq.isEmpty()){ + int[] cur = pq.poll(); + int u = cur[0]; + int c = cur[1]; + if(visited[u]) + continue; + + visited[u] = true; + answer += c; + count++; + if(count == N) + break; + for(int v = 0; v < N; v++){ + if(!visited[v]){ + pq.offer(new int[]{v, cost[u][v]}); + } + } + } + System.out.println(answer); + } +} + +```