Cod sursa(job #1113981)

Utilizator EuBossuletMuntea Andrei EuBossulet Data 21 februarie 2014 09:24:08
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator fpc Status done
Runda Arhiva educationala Marime 0.67 kb
Program roy_floyd;
var a:array[1..100,1..100] of integer;
    f,q:text;
    k,i,j,n,m:byte;
begin
assign(f,'royfloyd.in');
reset(f);
assign(q,'royfloyd.out');
rewrite(q);
readln(f,n);
for i:=1 to n do
    for j:=1 to n do begin read(f,a[i,j]);
                           if (i<>j) and (a[i,j]=0) then a[i,j]:=maxint;
                     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] 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]=maxint then write(q,0,' ')
                                       else write(q,a[i,j],' ');
    writeln(q);
end;
close(f);
close(q);
end.