Pagini recente » Cod sursa (job #1810983) | Cod sursa (job #290657) | Cod sursa (job #2268783) | Cod sursa (job #24171) | Cod sursa (job #165185)
Cod sursa(job #165185)
#include <stdio.h>
int n,a[110][110],c[110][110];
int main()
{
freopen("royfloyd.in","r",stdin);
freopen("royfloyd.out","w",stdout);
scanf("%d",&n);
int i,j,k;
for (i=1; i<=n; ++i)
{
for (j=1; j<=n; ++j)
{
scanf("%d",&a[i][j]);
c[i][j]=0x3f3f3f3f;
c[i][j]=a[i][j];
}
}
for (k=1; k<=n; ++k)
{
for (i=1; i<=n; ++i)
{
if (i==k) continue;
for (j=1; j<=n; ++j)
{
if (c[i][j]>c[i][k]+c[k][j]) c[i][j]=c[i][k]+c[k][j];
}
}
}
for (i=1; i<=n; ++i)
{
for (j=1; j<=n; ++j) { if (c[i][j]==0x3f3f3f3f) c[i][j]=0;printf("%d ",c[i][j]); }
printf("\n");
}
return 0;
}