From d7400ec95d01c4eb1935faf64ced0c55d55f1189 Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Wed, 21 Jul 2021 09:23:58 +0800 Subject: [PATCH] =?UTF-8?q?P1828=20[USACO3.2]=E9=A6=99=E7=94=9C=E7=9A=84?= =?UTF-8?q?=E9=BB=84=E6=B2=B9=20Sweet=20Butter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R53751682 --- Luogu/problem/P1828/P1828.cpp | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Luogu/problem/P1828/P1828.cpp diff --git a/Luogu/problem/P1828/P1828.cpp b/Luogu/problem/P1828/P1828.cpp new file mode 100644 index 00000000..804ff095 --- /dev/null +++ b/Luogu/problem/P1828/P1828.cpp @@ -0,0 +1,39 @@ +#include + +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; +}