Pagini recente » Cod sursa (job #1171227) | Cod sursa (job #1751438) | Cod sursa (job #711964) | Cod sursa (job #1752499) | Cod sursa (job #2964877)
#include <fstream>
using namespace std;
ifstream fin ("royfloyd.in");
ofstream fout("royfloyd.out");
int n,c[101][101];
void rw()
{
for(int z=0;z<n;z++)
{
for(int x=0;x<n;x++)
for(int y=0;y<n;y++)
{
if (x == y || x == z || y == z) continue;
c[x][y] = min(c[x][y],c[x][z]+c[z][y]);
}
}
}
void citire()
{
fin>>n;
for(int i=0;i<n;i++) for(int j=0;j<n;j++)
{
fin>>c[i][j];
if (c[i][j]==0)
c[i][j]=123856916;
}
}
void afisare()
{
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
if (c[i][j]==123856916)
fout<<"0 ";
else
fout<<c[i][j]<<' ';
fout<<'\n';
}
}
int main()
{
citire();
rw();
afisare();
return 0;
}