Cod sursa(job #1424466)

Utilizator ButnaruButnaru George Butnaru Data 24 aprilie 2015 15:25:43
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator fpc Status done
Runda Arhiva educationala Marime 0.55 kb
program roy;
type vector1=array[0..101,0..101] of longint;
var t:vector1;
    k,n,i,j:longint;
    f1,f2:text;
begin
assign (f1,'royfloyd.in');
assign (f2,'royfloyd.out');
reset (f1);
rewrite (f2);
readln (f1,n);
for i:=1 to n do
for j:=1 to n do
read (f1,t[i,j]);
for k:=1 to n do
for i:=1 to n do
for j:=1 to n do
if (i<>j) and (t[i,k]<>0) and (t[k,j]<>0) then
if (t[i,j]=0) or (t[i,j]>t[i,k]+t[k,j]) then t[i,j]:=t[i,k]+t[k,j];
for i:=1 to n do begin
for j:=1 to n do
write (f2,t[i,j],' ');
writeln (f2);
end;
close (f1);
close (f2);
end.