Pagini recente » Cod sursa (job #296898) | Cod sursa (job #3280169) | Cod sursa (job #383604) | Cod sursa (job #1951043) | Cod sursa (job #338839)
Cod sursa(job #338839)
Program royfloyd;
var f,g:text; a:array[1..100,1..100]of longint;
i,j,n:byte;
function minim (x,y:longint):longint;
begin
if x<y then exit (x) else exit (y);
end;
procedure alg_royfloyd;
var x,y,z:byte;
begin
for x:=1 to n do
for y:=1 to n do
for z:=1 to n do
if (x<>y) and (x<>z) and (y<>z) then a[y,z]:=minim (a[y,z],a[y,x]+a[x,z]);
end;
begin
assign (f,'royfloyd.in'); reset (f);
assign (g,'royfloyd.out'); rewrite (g);
readln (f,n);
for i:=1 to n do begin
for j:=1 to n do read (f,a[i,j]);
if a[i,j]=0 then a[i,j]:=maxlongint;
readln (f);
end;
alg_royfloyd;
for i:=1 to n do begin
for j:=1 to n do
if a[i,j]=maxlongint then write (g,0,' ') else write (g,a[i,j],' ');
writeln (g);
end;
close (f); close (g);
end.