Pagini recente » Cod sursa (job #2853732) | Cod sursa (job #3201725) | Cod sursa (job #1254644) | Cod sursa (job #246906) | Cod sursa (job #2964896)
#include <fstream>
#define NMAX 10005
#define INF 1000000005
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int n, m;
int c[NMAX][NMAX];
int i, j, x, y, z;
int main()
{
fin >>n;
for (i = 1; i <= n; ++i)
for (j = 1; j <= n; ++j)
if (i != j) c[i][j] = INF;
for (i = 1; i <= n; ++i)
for (j = 1; j <= n; ++j)
fin >>c[i][j];
for (z = 1; z <= n; ++z)
for (x = 1; x <= n; ++x)
for (y = 1; y <= n; ++y)
c[x][y] = min(c[x][y], c[x][z] + c[z][y]);
for (i = 1; i <= n; ++i)
{
for (j = 1; j <= n; ++j)
if (c[i][j] != INF) fout <<c[i][j]<<' ';
else fout <<0<<' ';
fout <<'\n';
}
fout.close();
return 0;
}