-
Notifications
You must be signed in to change notification settings - Fork 0
/
14938.cpp
32 lines (30 loc) · 799 Bytes
/
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
#include <cstdio>
#include <algorithm>
using namespace std;
int N,M,R,item[101],dist[101][101],inf=9e8,ans;
int main(){
scanf("%d%d%d",&N,&M,&R);
for(int i=1;i<=N;i++) scanf("%d",&item[i]);
for(int i=1;i<=N;i++){
for(int j=1;j<=N;j++){
if(i!=j) dist[i][j] = inf;
}
}
while(R--){
int a,b,l;
scanf("%d%d%d",&a,&b,&l);
dist[a][b] = min(dist[a][b],l);
dist[b][a] = min(dist[b][a],l);
}
for(int k=1;k<=N;k++)
for(int i=1;i<=N;i++)
for(int j=1;j<=N;j++) dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]);
for(int i=1;i<=N;i++){
int sum=0;
for(int j=1;j<=N;j++){
if(dist[i][j]<=M) sum+=item[j];
}
ans = max(ans,sum);
}
printf("%d",ans);
}