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

B3647 【模板】Floyd

https://www.luogu.com.cn/record/130409897
This commit is contained in:
Baoshuo Ren 2023-10-19 19:55:56 +08:00
parent 13b4867010
commit b294528f34
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

47
Luogu/B3647/B3647.cpp Normal file
View File

@ -0,0 +1,47 @@
#include <iostream>
#include <cstring>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 105;
int n, m, f[N][N];
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
memset(f, 0x3f, sizeof(f));
for (int i = 1, u, v, w; i <= m; i++) {
cin >> u >> v >> w;
f[u][v] = f[v][u] = w;
}
for (int i = 1; i <= n; i++) {
f[i][i] = 0;
}
for (int k = 1; k <= n; k++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
f[i][j] = std::min(f[i][j], f[i][k] + f[k][j]);
}
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cout << f[i][j] << ' ';
}
cout << endl;
}
return 0;
}