Cod sursa(job #894873)
#include<fstream>
#define dmax 102
using namespace std;
ifstream in("royfloyd.in");
ofstream out("royfloyd.out");
int n, cost[dmax][dmax], dist[dmax][dmax];
int main()
{
in>>n;
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++)
{
in>>cost[i][j];
dist[i][j] = cost[i][j];
}
in.close();
for(int k=1; k<=n; k++)
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++)
if(dist[i][k] && dist[k][j] && i!=j)
if(dist[i][k] + dist[k][j] < dist[i][j] || dist[i][j] == 0)
dist[i][j] = dist[i][k] + dist[k][j];
for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++)
out<<dist[i][j]<<" ";
out<<'\n';
}
out.close();
return 0;
}