比赛 |
防止颓废的小练习v0.1 |
评测结果 |
AAAAAAAAAA |
题目名称 |
文化之旅 |
最终得分 |
100 |
用户昵称 |
rewine |
运行时间 |
0.015 s |
代码语言 |
C++ |
内存使用 |
0.39 MiB |
提交时间 |
2016-10-17 11:41:03 |
显示代码纯文本
#include <bits/stdc++.h>
using std :: min;
const int INF = 999999;
int n,k,m,s,t,dist[101][101],c[101],a[101][101];
int main() {
freopen("culture.in","r",stdin);
freopen("culture.out","w",stdout);
scanf("%d%d%d%d%d",&n,&k,&m,&s,&t);
for (int i = 1;i <= n;i++)
for (int j = 1;j <= n;j++) dist[i][j] = INF;
for (int i = 1;i <= n;i++) scanf("%d",&c[i]);
for (int i = 1;i <= k;i++)
for (int j = 1;j <= k;j++)
scanf("%d",&a[i][j]);
for (int i = 1;i <= m;i++) {
int a1,b1,c1;
scanf("%d%d%d",&a1,&b1,&c1);
dist[a1][b1] = dist[b1][a1] = c1;
}
for (int i = 1;i <= n;i++)
for (int j = 1;j <= n;j++)
if (a[c[i]][c[j]]) dist[i][j] = INF;
for (int k = 1;k <= n;k++) //floyd
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]);
if (dist[s][t] == INF) printf("%d",-1);
else printf("%d",dist[t][s]);
}