Cod sursa(job #1174013)

Utilizator DjokValeriu Motroi Djok Data 21 aprilie 2014 17:03:32
Problema Floyd-Warshall/Roy-Floyd Scor 90
Compilator fpc Status done
Runda Arhiva educationala Marime 0.81 kb
const inf=1 shl 30;
 var a:array[1..101,1..101] of longint;
     i,j,k,n:longint;
     bif,bof:array[1..1 shl 16] of char;

begin
 assign(input,'royfloyd.in');
 assign(output,'royfloyd.out');
 reset(input);
 rewrite(output);
 settextbuf(input,bif);
 settextbuf(output,bof);
  readln(n);

   for i:=1 to n do
    for j:=1 to n do
     begin
      read(k);
      if k=0 then a[i][j]:=inf
             else a[i][j]:=k;
     end;

   for k:=1 to n do
    for i:=1 to n do
     for j:=1 to n do
       if (a[i][j]>a[i][k]+a[k][j]) and (i<>j) then a[i][j]:=a[i][k]+a[k][j];

   for i:=1 to n do
    begin
     for j:=1 to n do
      if a[i][j]=inf then write('0 ')
                     else write(a[i][j],' ');
     writeln;
    end;

 close(input);
 close(output);
{Totusi este trist in lume}
end.