-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathluogu.1078.cpp
45 lines (43 loc) · 942 Bytes
/
luogu.1078.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
#include <cstdio>
#include <cstring>
using namespace std;
int n,k,m,s,t,temp;
int wh[110],fl[110][110];;
bool bc[110][110];
int main(){
memset(fl,9999,sizeof(fl));
scanf("%d%d%d%d%d",&n,&k,&m,&s,&t);
for(int i=0;i<n;i++){
scanf("%d",&temp);
wh[i]=temp-1;
}
for(int i=0;i<k;i++){
for(int j=0;j<k;j++){
scanf("%d",&temp);
if(temp==0) bc[i][j]=false;
else bc[i][j]=true;
}
}
//以下代码看了标称才打出来
for(int i=0;i<m;i++){
int u,v,d;
scanf("%d%d%d",&u,&v,&d);
if(!bc[wh[u-1]][wh[v-1]]){
if(d<fl[v-1][u-1]) fl[v-1][u-1]=d;
}
if(!bc[wh[v-1]][wh[u-1]]){
if(d<fl[u-1][v-1]) fl[u-1][v-1]=d;
}
}
for(int k=0;k<n;k++){
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(!bc[wh[k]][wh[i]]&&!bc[wh[j]][wh[i]]&&!bc[wh[j]][wh[k]]){
if(fl[i][k]+fl[k][j]<fl[i][j]) fl[i][j]=fl[k][j]+fl[i][k];
}
}
}
}
if(fl[s-1][t-1]>=0x7f) printf("-1");
else printf("%d",fl[s-1][t-1]);
}