Pagini recente » Cod sursa (job #445627) | Cod sursa (job #1320632) | Cod sursa (job #2020408) | Cod sursa (job #2160409) | Cod sursa (job #338841)
Cod sursa(job #338841)
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) and (a[y,x]<>maxlongint) and (a[x,z]<>maxlongint) then a[x,y]:=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.