From a21741c55ac2693e8737c4d6e38fced1acc138fe Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Sat, 3 Jul 2021 10:36:57 +0800 Subject: [PATCH] =?UTF-8?q?P3371=20=E3=80=90=E6=A8=A1=E6=9D=BF=E3=80=91?= =?UTF-8?q?=E5=8D=95=E6=BA=90=E6=9C=80=E7=9F=AD=E8=B7=AF=E5=BE=84=EF=BC=88?= =?UTF-8?q?=E5=BC=B1=E5=8C=96=E7=89=88=EF=BC=89=20[70'=20Code]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R52310790 --- Luogu/problem/P3371/P3371.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Luogu/problem/P3371/P3371.cpp diff --git a/Luogu/problem/P3371/P3371.cpp b/Luogu/problem/P3371/P3371.cpp new file mode 100644 index 00000000..07c4dbd5 --- /dev/null +++ b/Luogu/problem/P3371/P3371.cpp @@ -0,0 +1,34 @@ +#include + +using namespace std; + +int n, m, s; +long long u, v, w, f[10005][10005]; + +int main() { + scanf("%d%d%d", &n, &m, &s); + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + f[i][j] = i == j ? 0 : INT_MAX; + } + } + for (int i = 0; i < m; i++) { + scanf("%d%d%d", &u, &v, &w); + f[u][v] = min(f[u][v], w); + } + for (int k = 1; k <= n; k++) { + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + if (i == k || f[i][k] == INT_MAX) { + continue; + } + f[i][j] = min(f[i][j], f[i][k] + f[k][j]); + } + } + } + for (int i = 1; i <= n; i++) { + printf("%d ", f[s][i]); + } + printf("\n"); + return 0; +}