Skip to content

Commit 5b35e94

Browse files
authored
[20250820] BOJ / G4 / 서강그라운드 / 김수연
1 parent e4ebc35 commit 5b35e94

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
```java
2+
import java.util.*;
3+
import java.io.*;
4+
5+
public class Main {
6+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
static StringTokenizer st;
8+
static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());}
9+
static int nextInt() {return Integer.parseInt(st.nextToken());}
10+
11+
static int n, m, r, answer = 0;
12+
static int[] item;
13+
static int[][] dist;
14+
public static void main(String[] args) throws Exception {
15+
nextLine();
16+
n = nextInt();
17+
m = nextInt();
18+
r = nextInt();
19+
item = new int[n+1];
20+
dist = new int[n+1][n+1];
21+
for (int i = 1; i <= n; i++) {
22+
Arrays.fill(dist[i], 16);
23+
dist[i][i] = 0;
24+
}
25+
nextLine();
26+
for (int i = 1; i <= n; i++) item[i] = nextInt();
27+
for (int i = 0; i < r; i++) {
28+
nextLine();
29+
int a = nextInt();
30+
int b = nextInt();
31+
int l = nextInt();
32+
dist[a][b] = l;
33+
dist[b][a] = l;
34+
}
35+
36+
floyd();
37+
System.out.println(answer);
38+
}
39+
40+
static void floyd() {
41+
for (int k = 1; k <= n; k++) {
42+
for (int i = 1; i <= n; i++) {
43+
for (int j = 1; j <= n; j++) {
44+
if (dist[i][j] > dist[i][k] + dist[k][j]) {
45+
dist[i][j] = dist[i][k] + dist[k][j];
46+
}
47+
}
48+
}
49+
}
50+
solve();
51+
}
52+
53+
static void solve() {
54+
for (int i = 1; i <= n; i++) {
55+
int sum = 0;
56+
for (int j = 1; j <= n; j++) {
57+
if (dist[i][j] <= m) sum += item[j];
58+
}
59+
answer = Math.max(answer, sum);
60+
}
61+
}
62+
}
63+
```

0 commit comments

Comments
 (0)