-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbaekjoon14938.cpp
More file actions
52 lines (42 loc) · 857 Bytes
/
baekjoon14938.cpp
File metadata and controls
52 lines (42 loc) · 857 Bytes
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
#include <iostream>
#include <algorithm>
#define INF 987654321
using namespace std;
int n, m, r, item[101], arr[101][101], from, to, cost;
int main() {
cin >> n >> m >> r;
for (int i = 1; i <= n; i++) {
cin >> item[i];
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
arr[i][j] = INF;
}
}
for (int i = 0; i < r; i++) {
cin >> from >> to >> cost;
arr[from][to] = cost;
arr[to][from] = cost;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
for (int k = 1; k <= n; k++) {
if (j == k)
continue;
else
arr[j][k] = min(arr[j][k], arr[j][i] + arr[i][k]);
}
}
}
int answer = 0;
for (int i = 1; i <= n; i++) {
int temp = item[i];
for (int j = 1; j <= n; j++) {
if (arr[i][j] <= m) {
temp += item[j];
}
}
answer = max(answer, temp);
}
cout << answer;
}