-
Notifications
You must be signed in to change notification settings - Fork 566
/
Copy path14938.cpp
71 lines (60 loc) · 1.27 KB
/
14938.cpp
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
64
65
66
67
68
69
70
71
// Authored by : scsc3204
// Co-authored by : -
// http://boj.kr/602ee20238604104978dd0b9ca245a34
#include <bits/stdc++.h>
using namespace std;
int n, m, r;
const int INF = 987987987;
int item[102];
bool vis[102];
int d[102][102];
int nxt[102][102];
void visit(int i, int j) {
int cur = i;
while(cur != j) {
vis[cur] = 1;
cur = nxt[cur][j];
}
vis[j] = 1;
}
int main(void){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> r;
for(int i = 1; i <= n; i++) {
int sc; cin >> sc;
item[i] = sc;
}
for(int i = 1; i <= n; i++) {
fill(d[i], d[i] + n + 1, INF);
d[i][i] = 0;
}
int x, y, dist;
while(r--) {
cin >> x >> y >> dist;
d[x][y] = dist; d[y][x] = dist;
nxt[x][y] = y; nxt[y][x] = x;
}
for(int k = 1; k <= n; k++)
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++) {
int tmp = d[i][k] + d[k][j];
if(tmp < d[i][j]) {
d[i][j] = tmp;
nxt[i][j] = nxt[i][k];
}
}
int ans = 0, tmp;
for(int i = 1; i <= n; i++){
tmp = 0;
fill(vis + 1, vis + n + 1, 0);
for(int j = 1; j <= n; j++) {
if(d[i][j] > m) continue;
visit(i, j);
}
for(int j = 1; j <= n; j++)
if(vis[j]) tmp += item[j];
ans = max(ans, tmp);
}
cout << ans;
}