Pagini recente » Cod sursa (job #1821099) | Cod sursa (job #395164) | Cod sursa (job #1323362) | Cod sursa (job #1098300) | Cod sursa (job #1743504)
#include <cstdio>
#include <algorithm>
#define in "royfloyd.in"
#define out "royfloyd.out"
#define NMAX 100 + 7
#define inf 1000 + 7
using namespace std;
int n, mat[NMAX][NMAX];
inline void getInput()
{
scanf("%d ", &n);
for(int i = 1; i<= n; ++i)
{
for(int j = 1; j<= n; ++j)
{
scanf("%d ", &mat[i][j]);
if(mat[i][j] == 0) mat[i][j] = inf;
}
}
}
inline void buildDynamic()
{
for(int k = 1; k<= n; ++k)
{
for(int i = 1; i<= n; ++i)
{
if(i == k) continue;
for(int j = 1; j<= n; ++j)
{
if(j == i || j == k) continue;
mat[i][j] = min(mat[i][j], mat[i][k] + mat[k][j]);
}
}
}
}
inline void giveOutput()
{
for(int i = 1; i<= n; ++i)
{
for(int j = 1; j<= n; ++j)
{
if(mat[i][j] >= inf) mat[i][j] = 0;
printf("%d ", mat[i][j]);
}
printf("\n");
}
}
int main()
{
freopen(in, "r", stdin);
freopen(out, "w", stdout);
getInput();
buildDynamic();
giveOutput();
return 0;
}