Pagini recente » Cod sursa (job #2900281) | Cod sursa (job #1930532) | Cod sursa (job #2143274) | Cod sursa (job #510539) | Cod sursa (job #1889142)
#include <cstdio>
using namespace std;
const int nmx = 102;
int n,mat[nmx][nmx];
void citire()
{
scanf("%d", &n);
for(int i = 1; i <= n; ++i)
for(int j = 1 ; j <= n; ++j)
scanf("%d", &mat[i][j]);
}
void calcul()
{
for(int k = 1; k <= n; ++k)
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
if(i != j && mat[i][k] && mat[k][j] && (not mat[i][j] || mat[i][j] > mat[i][k] + mat[k][j]))
mat[i][j] = mat[i][k] + mat[k][j];
}
void afish()
{
for(int i = 1; i <= n; ++i)
{
for(int j = 1; j <= n; ++j)
printf("%d ", mat[i][j]);
printf("\n");
}
}
int main()
{
freopen("royfloyd.in", "r", stdin);
freopen("royfloyd.out", "w", stdout);
citire();
calcul();
afish();
return 0;
}