Pagini recente » Cod sursa (job #214372) | Cod sursa (job #534636) | Cod sursa (job #2706918) | Cod sursa (job #1858776) | Cod sursa (job #3192640)
#include <fstream>
#define INF 100000
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int n,mat[105][105];
int main()
{
fin>>n;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
fin>>mat[i][j];
if(!mat[i][j])
mat[i][j]=INF;
}
for(int z=1;z<=n;z++)
for(int x=1;x<=n;x++)
for(int y=1;y<=n;y++)
if(mat[x][z]+mat[z][y]<mat[x][y] && x!=y)
mat[x][y]=mat[x][z]+mat[z][y];
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
if(mat[i][j]!=INF)
fout<<mat[i][j]<<' ';
else
fout<<"0 ";
fout<<'\n';
}
return 0;
}