You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.2 KiB

2 years ago
#include <bits/stdc++.h>
using namespace std;
const int N = 814;
const int INF = 0x3f3f3f3f;
int id[N];
int a, b, c, g[N][N], res = INF;
int main() {
2 years ago
#ifndef ONLINE_JUDGE
freopen("P1828_11.in", "r", stdin);
// 参考答案8
#endif
2 years ago
// 加快读入
ios::sync_with_stdio(false), cin.tie(0);
int p, n, m; // p只奶牛n个牧场m条边
cin >> p >> n >> m;
memset(g, 0x3f, sizeof g);
for (int i = 1; i <= n; i++) g[i][i] = 0; // 初始化
for (int i = 1; i <= p; i++) cin >> id[i]; // i号奶牛在id[i]这个牧场
while (m--) {
cin >> a >> b >> c;
g[a][b] = g[b][a] = min(c, g[a][b]);
}
// 标准的Floyd板子
for (int k = 1; k <= n; k++)
for (int i = 1; i <= n; i++) {
if (g[i][k] == INF) continue; // floyd小优化
for (int j = 1; j <= n; j++)
if (g[i][j] > g[i][k] + g[k][j])
g[j][i] = g[i][j] = g[i][k] + g[k][j];
}
for (int i = 1; i <= n; i++) { // 每个牧场出发
int ans = 0;
for (int j = 1; j <= p; j++) ans += g[i][id[j]];
2 years ago
if (ans >= 0) res = min(res, ans);
2 years ago
}
printf("%d", res);
return 0;
}