236
>
//Roy-Warshall - det matr drumurilor din matr de adiacenta
#include <stdio.h>
#include <conio.h>
int min(int a, int b)
{
if(a<=b) return a;
else return b;
}
void main()
{
int i,j,k,n,a[20][20];
FILE *f=fopen("c:intrare.txt","r");
fscanf(f,"%d",&n);
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
fscanf(f,"%d",&a[i][j]);
for(k=1;k<=n;k++)
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if((a[i][j]==0)&&(i!=k)&&(j!=k)) a[i][j]=min(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");
}
getch();
clrscr();
}