From 7741c40d36d952e68de9f6a7115a6424954af9a2 Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Sat, 17 Jul 2021 19:35:19 +0800 Subject: [PATCH] =?UTF-8?q?854.=20Floyd=E6=B1=82=E6=9C=80=E7=9F=AD?= =?UTF-8?q?=E8=B7=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.acwing.com/problem/content/submission/code_detail/6498911/ --- AcWing/854/854.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 AcWing/854/854.cpp diff --git a/AcWing/854/854.cpp b/AcWing/854/854.cpp new file mode 100644 index 00000000..0ae51786 --- /dev/null +++ b/AcWing/854/854.cpp @@ -0,0 +1,34 @@ +#include + +using namespace std; + +int n, m, k, x, y, z, f[205][205]; + +int main() { + cin >> n >> m >> k; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + f[i][j] = i == j ? 0 : 0x3f3f3f3f3f; + } + } + for (int i = 1; i <= m; i++) { + cin >> x >> y >> z; + f[x][y] = min(f[x][y], z); + } + for (int k = 1; k <= n; k++) { + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + f[i][j] = min(f[i][j], f[i][k] + f[k][j]); + } + } + } + for (int i = 1; i <= k; i++) { + cin >> x >> y; + if (f[x][y] > 0x1fffffff) { + cout << "impossible" << endl; + } else { + cout << f[x][y] << endl; + } + } + return 0; +}