From d89cd367ab0fb5ca70190cc64ea69bdc90cf12ce Mon Sep 17 00:00:00 2001 From: LiiNi-coder <97495437+LiiNi-coder@users.noreply.github.com> Date: Mon, 11 Aug 2025 23:57:40 +0900 Subject: [PATCH] =?UTF-8?q?[20250811]=20BOJ=20/=20G4=20/=20=EC=84=9C?= =?UTF-8?q?=EA=B0=95=EA=B7=B8=EB=9D=BC=EC=9A=B4=EB=93=9C=20/=20=EC=9D=B4?= =?UTF-8?q?=EC=9D=B8=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...70\353\235\274\354\232\264\353\223\234.md" | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 "LiiNi-coder/202508/11 BOJ \354\204\234\352\260\225\352\267\270\353\235\274\354\232\264\353\223\234.md" diff --git "a/LiiNi-coder/202508/11 BOJ \354\204\234\352\260\225\352\267\270\353\235\274\354\232\264\353\223\234.md" "b/LiiNi-coder/202508/11 BOJ \354\204\234\352\260\225\352\267\270\353\235\274\354\232\264\353\223\234.md" new file mode 100644 index 00000000..eb018d12 --- /dev/null +++ "b/LiiNi-coder/202508/11 BOJ \354\204\234\352\260\225\352\267\270\353\235\274\354\232\264\353\223\234.md" @@ -0,0 +1,68 @@ +```java +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class Main { + private static BufferedReader br; + private static StringTokenizer st; + private static int n; + private static int m; + private static int r; + private static int[][] dist; + private static int[] items; + private static final int INF = 1_000_000; + + public static void main(String[] args) throws IOException { + br = new BufferedReader(new InputStreamReader(System.in)); + String[] temp = br.readLine().split(" "); + n = Integer.parseInt(temp[0]); + m = Integer.parseInt(temp[1]); + r = Integer.parseInt(temp[2]); + items = new int[n + 1]; + st = new StringTokenizer(br.readLine()); + for (int i = 1; i <= n; i++) { + items[i] = Integer.parseInt(st.nextToken()); + } + + dist = new int[n + 1][n + 1]; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + if (i == j) dist[i][j] = 0; + else dist[i][j] = INF; + } + } + for (int i = 0; i < r; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + int c = Integer.parseInt(st.nextToken()); + dist[a][b] = Math.min(dist[a][b], c); + dist[b][a] = Math.min(dist[b][a], c); + } + //플로이드-워셜 + for (int k = 1; k <= n; k++) { + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + if (dist[i][k] != INF && dist[k][j] != INF) { + dist[i][j] = Math.min(dist[i][j], dist[i][k] + dist[k][j]); + } + } + } + } + + int maxItems = 0; + for (int i = 1; i <= n; i++) { + int currentItems = 0; + for (int j = 1; j <= n; j++) { + if (dist[i][j] <= m) { + currentItems += items[j]; + } + } + maxItems = Math.max(maxItems, currentItems); + } + System.out.println(maxItems); + } +} +```