File tree Expand file tree Collapse file tree 1 file changed +63
-0
lines changed
Expand file tree Collapse file tree 1 file changed +63
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments