Pagini recente » Cod sursa (job #2229064) | Cod sursa (job #2022893) | Cod sursa (job #1551760) | Cod sursa (job #7390) | Cod sursa (job #291749)
Cod sursa(job #291749)
type matrice=array[1..100,1..100]of integer;
const max=1001;
var n,i,j:byte;
l:integer;
a:matrice;
procedure royfloyd(var a:matrice;n:byte);
var i,j,k:byte;
l:integer;
begin
for k:=1 to n do
for i:=1 to n do if i<>k then
for j:=1 to n do if(j<>k)and(j<>i)then
begin
l:=a[i,k]+a[k,j];
if l<a[i,j] then a[i,j]:=l;
end;
end;
procedure afisare(var a:matrice;n:byte);
var i,j:byte;
l:integer;
begin
for i:=1 to n do
begin
for j:=1 to n do begin
l:=a[i,j];
if l<>max then write(l,' ')
else write('0 ');
end;
writeln;
end;
end;
begin
assign(input,'royfloyd.in');
reset(input);
assign(output,'royfloyd.out');
rewrite(output);
readln(n);
for i:=1 to n do
begin
for j:=1 to n do begin
read(l);
if l=0 then a[i,j]:=max
else a[i,j]:=l;
end;
readln;
end;
royfloyd(a,n);
afisare(a,n);
close(input);
close(output);
end.