#include<iostream>
#include<cstdio>
using namespace std;
const int INF = 0x3f3f3f3f;
int main(void)
{
int e[10][10] = { 0 }, dis[10], book[10], i, j, k, n, m, t1, t2, t3;
cout << "本程序演示Floyd算法" << endl;
cout << "请输入顶点数和边数:";
cin >> n >> m;
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j++)
if (i != j)
e[i][j] = INF;
cout << "下面请输入权重数据";
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][j]>e[i][k] + e[k][j])
e[i][j] = e[i][k] + e[k][j];
cout << "下面输出多源最短路径" << endl;
for (i = 1; i <= n; i++)
{
for (j = 1; j <= n; j++)
{
cout << e[i][j] << " ";
}
cout << endl;
}
return 0;
}
FLOYD算法
最新推荐文章于 2021-03-26 22:33:48 发布