Pagini recente » Cod sursa (job #1203142) | Cod sursa (job #913471)
Cod sursa(job #913471)
type matrice=array[1..100,1..100] of integer;
var a:matrice;
i,j,n,k:integer;
f,g:text;
begin
assign(f,'royfloyd.in');
reset(f);
readln(f,n);
for i:=1 to n do
begin
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;
readln(f);
end;
close(f);
for k:=1 to n do
for i:=1 to n do
for j:=1 to n do
if (a[i,k]<>maxint) and (a[k,j]<>maxint) then
if (a[i,j]>a[i,k]+a[k,j]) then
begin
a[i,j]:=a[i,k]+a[k,j];
end;
assign(g,'royfloyd.out');
rewrite(g);
for i:=1 to n do
begin
for j:=1 to n do
if a[i,j]=maxint then write(g,0,' ') else
write(g,A[i,j],' ');
writeln(g);
end;
close(g);
end.