0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 18:52:02 +00:00

P3371 【模板】单源最短路径(弱化版) [70' Code]

R52310790
This commit is contained in:
Baoshuo Ren 2021-07-03 10:36:57 +08:00 committed by Baoshuo Ren
parent 346f5a520b
commit a21741c55a
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

View File

@ -0,0 +1,34 @@
#include <bits/stdc++.h>
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;
}