From 5fb9cb25cef00f7407d9f4699fb429dc7492f6cc Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Tue, 13 Jul 2021 21:53:56 +0800 Subject: [PATCH] =?UTF-8?q?P6175=20=E6=97=A0=E5=90=91=E5=9B=BE=E7=9A=84?= =?UTF-8?q?=E6=9C=80=E5=B0=8F=E7=8E=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R53047373 --- Luogu/problem/P6175/P6175.cpp | 40 +++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Luogu/problem/P6175/P6175.cpp diff --git a/Luogu/problem/P6175/P6175.cpp b/Luogu/problem/P6175/P6175.cpp new file mode 100644 index 00000000..ef189737 --- /dev/null +++ b/Luogu/problem/P6175/P6175.cpp @@ -0,0 +1,40 @@ +#include + +using namespace std; + +long long n, m, u, v, d, f1[105][105], f2[105][105], ans = 0x3f3f3f3f; + +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + f1[i][j] = f2[i][j] = i == j ? 0 : 0x3f3f3f3f; + } + } + for (int i = 1; i <= m; i++) { + cin >> u >> v >> d; + f1[u][v] = min(f1[u][v], d); + f1[v][u] = min(f1[v][u], d); + f2[u][v] = min(f2[u][v], d); + f2[v][u] = min(f2[v][u], d); + } + for (int k = 1; k <= n; k++) { + for (int i = 1; i < k; i++) { + for (int j = i + 1; j < k; j++) { + ans = min(ans, f1[i][j] + f2[i][k] + f2[k][j]); + } + } + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + f1[i][j] = min(f1[i][j], f1[i][k] + f1[k][j]); + f1[j][i] = f1[i][j]; + } + } + } + if (ans == 0x3f3f3f3f) { + cout << "No solution." << endl; + } else { + cout << ans << endl; + } + return 0; +}