Pagini recente » Cod sursa (job #2289094) | Cod sursa (job #2888729) | Cod sursa (job #2092652) | Cod sursa (job #134222) | Cod sursa (job #2811008)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("royfloyd.in");
ofstream out("royfloyd.out");
const int MAXN = 1001;
int n, i, j ,k, x;
int dist[101][101];
void royfloyd()
{
for(k=1; k<=n; k++)
for(i=1; i<=n; i++)
for(j=1; j<=n; j++)
{
if(dist[i][j]>dist[i][k]+dist[k][j])
{
dist[i][j]=dist[i][k]+dist[k][j];
}
}
}
int main()
{
in>>n;
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++)
{
int x;
in>>x;
if(x == 0 && i!=j)
dist[i][j] = MAXN;
else
dist[i][j] = x;
}
royfloyd();
for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++)
if(dist[i][j] == MAXN)
out<<0<<" ";
else
out<<dist[i][j]<<" ";
out<<"\n";
}
return 0;
}