Cod sursa(job #409264)

Utilizator saodem74hieu tran saodem74 Data 3 martie 2010 15:41:06
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator fpc Status done
Runda Arhiva educationala Marime 0.74 kb
uses    math;
const   tfi='royfloyd.in';
        tfo='royfloyd.out';
        maxn=111;
var     fi,fo:text;
        i,j,k,n:longint;
        a:array[0..maxn,0..maxn] of longint;

begin
        assign(Fi,tfi); reset(fi);
        assign(Fo,tfo); rewrite(fo);
        read(fi,n);
        for i:=1 to n do
         for j:=1 to n do read(fi,a[i][j]);
        for k:=1 to n do
         for i:=1 to n do
          for j:=1 to n do
          if (i<>j) and (i<>k) and (k<>j) then
          if (a[i,k]*a[i,j]*a[k,j]<>0) then
           a[i,j]:=min(a[i,k]+a[k,j],a[i,j]);
          for i:=1 to n do
           begin
            for j:=1 to n do write(fo,a[i,j],' ');
            writeln(fo);
           end;
        close(fi); close(Fo);
end.