比赛 |
ctime蒟蒻生日赛 |
评测结果 |
AAAAAAAAAA |
题目名称 |
文化之旅 |
最终得分 |
100 |
用户昵称 |
胡嘉兴 |
运行时间 |
0.084 s |
代码语言 |
C++ |
内存使用 |
0.22 MiB |
提交时间 |
2017-10-17 15:09:38 |
显示代码纯文本
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
#define N 105
int M = 99999999;
int main()
{
int n, k, m, s, t, i, j, l, t1, t2, t3, f[N][N], e[N][N], book[N];
freopen("culture.in", "r", stdin);
freopen("culture.out", "w", stdout);
scanf("%d%d%d%d%d", &n, &k, &m, &s, &t);
for(i = 0; i < N; i++)
{
for(j = 0; j < N; j++)
{
f[i][j] = 1;
e[i][j] = M;
if(i == j)
{
e[i][j] = 0;
}
}
}
for(i = 1; i <= n; i++)
{
scanf("%d", &book[i]);
}
for(i = 1; i <= k; i++)
{
for(j = 1; j <= k; j++)
{
scanf("%d", &t1);
if(t1 == 1)
{
f[i][j] = -1;
}
}
}
for(i = 0; i < m; i++)
{
scanf("%d%d%d", &t1, &t2, &t3);
if(e[t1][t2] != M)
{
if(e[t1][t2] > t3)
{
e[t1][t2] = t3;
e[t2][t1] = t3;
}
}
else
{
e[t1][t2] = t3;
e[t2][t1] = t3;
}
}
for(i = 1; i <= n; i++)
{
for(j = 1; j <= n; j++)
{
if(f[book[i]][book[j]] == -1)
{
e[i][j] = M;
}
if(f[book[j]][book[i]] == -1)
{
e[j][i] = M;
}
}
}
for(l = 1; l <= n; l++)
{
for(i = 1; i <= n; i++)
{
for(j = 1; j <= n; j++)
{
if(e[i][j] > e[i][l] + e[l][j])
{
e[i][j] = e[i][l] + e[l][j];
}
}
}
}
if(e[s][t] == M)
{
printf("-1\n");
}
else
{
printf("%d\n", e[s][t]);
}
fclose(stdin);
fclose(stdout);
return 0;
}