mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-12-24 03:31:59 +00:00
P3371 【模板】单源最短路径(弱化版) [70' Code]
R52310790
This commit is contained in:
parent
346f5a520b
commit
a21741c55a
34
Luogu/problem/P3371/P3371.cpp
Normal file
34
Luogu/problem/P3371/P3371.cpp
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user