Pagini recente » Rating Ionita Diana (dia0369) | Cod sursa (job #3281778) | Cod sursa (job #1055479) | Cod sursa (job #228504) | Cod sursa (job #156237)
Cod sursa(job #156237)
#include <stdio.h>
#define nmax 105
int n, i, j, k;
int a[nmax][nmax];
inline int min(int a, int b)
{
if(a > b) return b;
else return a;
}
int main()
{
freopen("royfloyd.in", "r", stdin);
freopen("royfloyd.out", "w", stdout);
scanf("%d", &n);
for(i = 1; i <= n; i++)
for(j = 1; j <= n; j++)
{
scanf("%d", &a[i][j]);
if(a[i][j] == 0 && i != j) a[i][j] = 10000;
}
for(k = 1; k <= n; k++)
for(i = 1; i <= n; i++)
for(j = 1; j <= n; j++)
a[i][j] = min(a[i][j], a[i][k] + a[k][j]);
for(i = 1; i <= n; i++)
{
for(j = 1; j <= n; j++)
printf("%d ", a[i][j]);
printf("\n");
}
return 0;
}