Cod sursa(job #412158)

Utilizator DanielGGlodeanu Ioan Daniel DanielG Data 5 martie 2010 13:18:50
Problema Floyd-Warshall/Roy-Floyd Scor 0
Compilator fpc Status done
Runda Arhiva educationala Marime 0.97 kb
const inf=10000;
var c,tata:array[1..5,1..5] of integer;
i,j,k,n:byte;
f:text;
procedure citire;
begin
assign(f,'royfloyd.in');reset(f);
read(f,n);
for i:=1 to n do
      for j:=1 to n do
        begin
        read(f,c[i,j]);
        if (i<>j) and (c[i,j]=0) then c[i,j]:=inf;
        end;
close(f);
end;
procedure royfloyd;
begin
for k:=1 to n do
        for i:=1 to n do
                for j:=1 to n do
                   if (c[i,k]<>inf) and (c[k,j]<>inf) then
                        if (c[i,j]>c[i,k]+c[k,j]) then
                                begin
                                  c[i,j]:=c[i,k]+c[k,j];
                                  tata[i,j]:=tata[k,j];
                                end;
end;
procedure scrie;
begin
assign(f,'royfloyd.out');rewrite(f);
for i:=1 to n do
        begin
        for j:=1 to n do
                write(f,c[i,j],' ');
        writeln(f);
        end;
close(f);
end;
begin
citire;
royfloyd;
scrie;
end.