From 5b35e94b2cf51729b765cfade2d25f4be43825dd Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Wed, 20 Aug 2025 14:52:45 +0900 Subject: [PATCH] =?UTF-8?q?[20250820]=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=EA=B9=80?= =?UTF-8?q?=EC=88=98=EC=97=B0?= 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" | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 "suyeun84/202508/20 BOJ G4 \354\204\234\352\260\225\352\267\270\353\235\274\354\232\264\353\223\234.md" diff --git "a/suyeun84/202508/20 BOJ G4 \354\204\234\352\260\225\352\267\270\353\235\274\354\232\264\353\223\234.md" "b/suyeun84/202508/20 BOJ G4 \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..6934930e --- /dev/null +++ "b/suyeun84/202508/20 BOJ G4 \354\204\234\352\260\225\352\267\270\353\235\274\354\232\264\353\223\234.md" @@ -0,0 +1,63 @@ +```java +import java.util.*; +import java.io.*; + +public class Main { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static StringTokenizer st; + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static int nextInt() {return Integer.parseInt(st.nextToken());} + + static int n, m, r, answer = 0; + static int[] item; + static int[][] dist; + public static void main(String[] args) throws Exception { + nextLine(); + n = nextInt(); + m = nextInt(); + r = nextInt(); + item = new int[n+1]; + dist = new int[n+1][n+1]; + for (int i = 1; i <= n; i++) { + Arrays.fill(dist[i], 16); + dist[i][i] = 0; + } + nextLine(); + for (int i = 1; i <= n; i++) item[i] = nextInt(); + for (int i = 0; i < r; i++) { + nextLine(); + int a = nextInt(); + int b = nextInt(); + int l = nextInt(); + dist[a][b] = l; + dist[b][a] = l; + } + + floyd(); + System.out.println(answer); + } + + static void floyd() { + for (int k = 1; k <= n; k++) { + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + if (dist[i][j] > dist[i][k] + dist[k][j]) { + dist[i][j] = dist[i][k] + dist[k][j]; + } + } + } + } + solve(); + } + + static void solve() { + for (int i = 1; i <= n; i++) { + int sum = 0; + for (int j = 1; j <= n; j++) { + if (dist[i][j] <= m) sum += item[j]; + } + answer = Math.max(answer, sum); + } + } +} +```