mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-12-24 18:31:59 +00:00
P1828 [USACO3.2]香甜的黄油 Sweet Butter
R53751682
This commit is contained in:
parent
cdd5086345
commit
d7400ec95d
39
Luogu/problem/P1828/P1828.cpp
Normal file
39
Luogu/problem/P1828/P1828.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int n, p, c, x, a, b, d, cnt[805], g[805][805], sum, ans = 0x3f3f3f3f;
|
||||
|
||||
int main() {
|
||||
cin >> n >> p >> c;
|
||||
for (int i = 1; i <= p; i++) {
|
||||
for (int j = 1; j <= p; j++) {
|
||||
g[i][j] = i == j ? 0 : 0x3f3f3f3f;
|
||||
}
|
||||
}
|
||||
for (int i = 1; i <= n; i++) {
|
||||
cin >> x;
|
||||
cnt[x]++;
|
||||
}
|
||||
for (int i = 1; i <= c; i++) {
|
||||
cin >> a >> b >> d;
|
||||
g[a][b] = d;
|
||||
g[b][a] = d;
|
||||
}
|
||||
for (int k = 1; k <= p; k++) {
|
||||
for (int i = 1; i <= p; i++) {
|
||||
for (int j = 1; j <= i; j++) {
|
||||
g[j][i] = g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 1; i <= p; i++) {
|
||||
sum = 0;
|
||||
for (int j = 1; j <= p; j++) {
|
||||
sum += g[i][j] * cnt[j];
|
||||
}
|
||||
ans = min(ans, sum);
|
||||
}
|
||||
cout << ans << endl;
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user