#include<iostream>
using namespace std;
int main() {
int e[10][10], i, j, k, m, n;
int t1, t2, t3;
int inf = 999999999;
cin >> n >> m;
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j++) {
if (i == j)
e[i][j] = 0;
else
e[i][j] = inf;
}
for (i = 1; i <= m; i++) {
cin >> t1 >> t2 >> t3;
e[t1][t2] = t3;
}
for (k = 1; k <= n; k++)//弗洛伊德算法
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j++)
if (e[i][k]<inf&&e[k][j]<inf&&e[i][j] > e[i][k] + e[k][j])
e[i][j] = e[i][k] + e[k][j];
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++)
cout << e[i][j]<<" ";
cout<<endl;
}
return 0;
}
Floyd
Posted waoyu
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Floyd相关的知识,希望对你有一定的参考价值。
以上是关于Floyd的主要内容,如果未能解决你的问题,请参考以下文章