From 04c6d341b64f3b858f8fb1a69360a80160dce97c Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Mon, 19 Jul 2021 19:44:55 +0800 Subject: [PATCH] =?UTF-8?q?P3905=20=E9=81=93=E8=B7=AF=E9=87=8D=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R53608296 --- Luogu/problem/P3905/P3905.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Luogu/problem/P3905/P3905.cpp diff --git a/Luogu/problem/P3905/P3905.cpp b/Luogu/problem/P3905/P3905.cpp new file mode 100644 index 00000000..64ec8a3c --- /dev/null +++ b/Luogu/problem/P3905/P3905.cpp @@ -0,0 +1,34 @@ +#include + +using namespace std; + +int n, m, u, v, w, d, a, b, f[105][105], g[105][105]; + +int main() { + cin >> n >> m; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + g[i][j] = f[i][j] = i == j ? 0 : 0x3f3f3f3f; + } + } + for (int i = 1; i <= m; i++) { + cin >> u >> v >> w; + f[u][v] = f[v][u] = w; + g[u][v] = g[v][u] = 0; + } + cin >> d; + for (int i = 1; i <= d; i++) { + cin >> u >> v; + g[u][v] = g[v][u] = f[u][v]; + } + for (int k = 1; k <= n; k++) { + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + g[i][j] = min(g[i][j], g[i][k] + g[k][j]); + } + } + } + cin >> a >> b; + cout << g[a][b] << endl; + return 0; +}