Pagini recente » Cod sursa (job #324443) | Cod sursa (job #1927795) | Cod sursa (job #140338) | Cod sursa (job #759235) | Cod sursa (job #1562088)
# include <cstdio>
# define N 110
using namespace std;
int n;
int a[N][N];
int main()
{
freopen("royfloyd.in", "r", stdin);
freopen("royfloyd.out", "w", stdout);
scanf("%d\n", &n);
for(int i=1; i<=n; ++i)
for(int j=1; j<=n; ++j)
scanf("%d ", &a[i][j]);
for(int k=1; k<=n; ++k)
for(int i=1; i<=n; ++i)
for(int j=1; j<=n; ++j)
if(a[i][k] && a[k][j] && i!=j && (a[i][k]+a[k][j]<a[i][j] || !a[i][j])) a[i][j]=a[i][k]+a[k][j];
for(int i=1; i<=n; ++i, printf("\n"))
for(int j=1; j<=n; ++j)
printf("%d ", a[i][j]);
}