-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14938.cpp
More file actions
88 lines (75 loc) · 1.49 KB
/
14938.cpp
File metadata and controls
88 lines (75 loc) · 1.49 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/**
* @file 14938.cpp
* @brief 서강그라운드
* @author Sam Kim (samkim2626@gmail.com)
*/
#include <iostream>
using namespace std;
#define INF 1e9
int n, m, r;
int t[101];
int g[101][101];
void floydWarshall()
{
for (int k = 1; k <= n; k++)
{
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
}
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
// input
cin >> n >> m >> r;
for (int i = 1; i <= n; i++)
{
cin >> t[i];
}
// for (int i = 0; i < n; i++)
// {
// for (int j = 0; j < n; j++)
// {
// if (i != j)
// {
// g[i][j] = INF;
// }
// }
// }
fill(g[0], g[0] + 10000, INF);
for (int i = 1; i <= n; i++)
{
g[i][i] = 0;
}
for (int i = 0; i < r; i++)
{
int a, b, l;
cin >> a >> b >> l;
g[a][b] = l;
g[b][a] = l;
}
floydWarshall();
// output
// 각 시작점으로부터 수색범위 내 아이템 합들을 비교
int ans = 0;
for (int i = 1; i <= n; i++) // 시작점
{
int sum = 0;
for (int j = 1; j <= n; j++) // 끝점
{
if (g[i][j] <= m)
{
sum += t[j];
}
}
ans = max(ans, sum);
}
cout << ans << '\n';
return 0;
}