Cod sursa(job #378937)

Utilizator cristinabCristina Brinza cristinab Data 29 decembrie 2009 23:56:48
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator fpc Status done
Runda Arhiva educationala Marime 0.8 kb
{algoritmul roy-floyd}
const inf=maxint div 2;

var c:array[1..100,1..100] of integer;
    n:byte;

procedure citire;
var i,j:byte;
begin
assign(input,'royfloyd.in'); reset(input);
readln(n);
for i:=1 to n do
    for j:=1 to n do
        begin
        read(c[i,j]);
        if (i<>j) and (c[i,j]=0) then c[i,j]:=inf;
        end;
close(input);
end;


procedure royfloyd;
var i,j,k:integer;
begin

for k:=1 to n do
    for i:=1 to n do
        for j:=1 to n do
            if c[i,k]+c[k,j]<c[i,j] then c[i,j]:=c[i,k]+c[k,j];
end;

procedure afisare;
var i,j:byte;
begin
assign(output,'royfloyd.out'); rewrite(output);
for i:=1 to n do
    begin
    for j:=1 to n do write(c[i,j],' ');
    writeln;
    end;
close(output);
end;

begin
citire;
royfloyd;
afisare;
end.