| Код | program minim_tree_prim; const maxn=100; var a:array[1..maxn,1..maxn]of integer; n,i,j:integer;
procedure solve; var sm,sp:set of 1..maxn; min,i,j,l,t:integer; begin min:=maxint; sm:=[1..n];sp:=[]; for i:=1 to n-1 do for j:=i+1 to n do if (a[i,j] < min) and (a[i,j] <> 0) then begin min:=a[i,j]; l:=i;t:=j; end; sp:=[l,t];sm:=sm-[l,t]; write(l,' ',t ,' '); while sm <> [] do begin min:=maxint; l:=0;t:=0; for i:=1 to n do if not (i in sp) then for j:=1 to n do if (j in sp) and (a[i,j] < min) and (a[i,j] <> 0) then begin min:=a[i,j]; l:=i;t:=j; end; sp:=sp+[l];sm:=sm-[l]; write(l,' ',t,' '); end; end;
begin read(n); for i:=1 to n do for j:=1 to n do read(a[i,j]); solve; end.
|
под дельфу сам переделаешь? |