|
|
|
@ -443,7 +443,51 @@ int main() {
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
#### [$P1828$ [$USACO3.2$] 香甜的黄油 $Sweet$ $Butter$](https://www.luogu.com.cn/problem/P1828)
|
|
|
|
|
```cpp {.line-numbers}
|
|
|
|
|
#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() {
|
|
|
|
|
#ifndef ONLINE_JUDGE
|
|
|
|
|
freopen("P1828_11.in", "r", stdin);
|
|
|
|
|
// 参考答案:8
|
|
|
|
|
#endif
|
|
|
|
|
// 加快读入
|
|
|
|
|
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]];
|
|
|
|
|
if (ans >= 0) res = min(res, ans);
|
|
|
|
|
}
|
|
|
|
|
printf("%d", res);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
SSL-1761(城市问题)
|
|
|
|
|
|
|
|
|
|