#include<bits/stdc++.h>
#include "iostream"
using namespace std;
#define INF 10000
#define n 4
#define m 4
void floydWarshall(int distance[][4])
{
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
{
int minimum = distance[i][j];
for(int k=i+1;k<j;k++)
minimum = min(minimum,distance[i][k]+distance[k][j]);
distance[i][j] = minimum;
}
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
cout<<distance[i][j]<<" ";
cout<<endl;
}
}
int main()
{
int graph[4][4] = { {0, 5, INF, 10},
{INF, 0, 3, INF},
{INF, INF, 0, 1},
{INF, INF, INF, 0} };
int distance[4][4];
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
distance[i][j] = graph[i][j];
floydWarshall(distance);
}
#include "iostream"
using namespace std;
#define INF 10000
#define n 4
#define m 4
void floydWarshall(int distance[][4])
{
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
{
int minimum = distance[i][j];
for(int k=i+1;k<j;k++)
minimum = min(minimum,distance[i][k]+distance[k][j]);
distance[i][j] = minimum;
}
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
cout<<distance[i][j]<<" ";
cout<<endl;
}
}
int main()
{
int graph[4][4] = { {0, 5, INF, 10},
{INF, 0, 3, INF},
{INF, INF, 0, 1},
{INF, INF, INF, 0} };
int distance[4][4];
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
distance[i][j] = graph[i][j];
floydWarshall(distance);
}
No comments:
Post a Comment