1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class B14938 {
static int N, M, R, S,E,D, max;
static final int MAX = 987654321;
static int[] item, visitDis;
static int [][] graph;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
M = Integer.parseInt(st.nextToken());
R = Integer.parseInt(st.nextToken());
graph = new int[N+1][N+1];
item = new int[N+1];
st = new StringTokenizer(br.readLine());
for (int i = 1; i <= N; i++) {
item[i] = Integer.parseInt(st.nextToken());
}
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
if(i!=j)
graph[i][j] = MAX;
}
}
for(int i=0;i<R;i++) {
st = new StringTokenizer(br.readLine());
S = Integer.parseInt(st.nextToken());
E = Integer.parseInt(st.nextToken());
D = Integer.parseInt(st.nextToken());
graph[S][E] =D ;
graph[E][S] =D;
}
for (int k = 1; k <= N; k++)
for (int i = 1; i <= N; i++)
for (int j = 1; j <= N; j++)
{
// 최단거리 갱신
if (graph[i][k] + graph[k][j] < graph[i][j])
graph[i][j] = graph[i][k] + graph[k][j];
}
for (int i = 1; i <= N; i++)
{
int cnt = 0;
for (int j = 1; j <= N; j++)
{
if (graph[i][j] <= M)
cnt += item[j];
}
max = Math.max(max, cnt);
}
System.out.println(max);
}
}
|