Pagini recente » Cod sursa (job #3252212) | Cod sursa (job #3259746) | Cod sursa (job #3206574) | Cod sursa (job #2159643) | Cod sursa (job #993074)
Cod sursa(job #993074)
#include<cstdio>
using namespace std;
int n,a[105][105];
int main()
{
int i,j,k;
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]);
for (k=1;k<=n;++k)
for (i=1;i<=n;++i)
for (j=1;j<=n;++j)
if (k!=i && k!=j && a[i][k]*a[k][j])
if (a[i][j]>a[i][k]+a[k][j])
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;
}