代码怎么试都没错啊,怎么只得40分,求帮助
type edge=record prev,endv,weight:longint; end;var elist:array[1..10000] of edge; g:array[1..100,1..100] of longint; i,j,n,p,min,tot,k,m:longint; t:edge;begin readln(n); {把图存入邻接矩阵} for i:=1 to n do begin for j:=1 to n do g[i,j]:=maxlongint; end; for i:=1 to n do begin for j:=1 to n do begin read(g[i,j]); end; end; {for i:=1 to n do begin for j:=1 to n do begin write(fo,g[i,j],' '); end; writeln(fo); end;} {建立边集数组,边集数组储存最小生成树用prim算法} {边集数组初始化,从顶点1开始,表示出顶点一到其他各顶点的权} for i:=1 to n-1 do {n各顶点的最小生成树有n-1条边} begin elist[i].prev:=1; elist[i].endv:=i+1; elist[i].weight:=g[1,i+1] end; k:=1;{生成第k边} while k<=n-1 do begin min:=maxlongint; m:=k; for j:=k to n-1 do begin if elist[j].weight<min then begin min:=elist[j].weight; m:=j; end else; end; if m<>k then begin t:=elist[k]; elist[k]:=elist[m]; elist[j]:=t; end else; j:=elist[k].endv;{j为新加入的顶点} {更新已有顶点到剩余其他顶点的最短距离} for i:=k+1 to n-1 do begin if g[j,elist[i].endv]<elist[i].weight then begin elist[i].prev:=j; elist[i].weight:=g[j,elist[i].endv]; end else; end; inc(k); end; tot:=0; for i:=1 to n-1 do begin inc(tot,elist[i].weight); end; writeln(tot); end.
type edge=record prev,endv,weight:longint; end;var elist:array[1..10000] of edge; g:array[1..100,1..100] of longint; i,j,n,p,min,tot,k,m:longint; t:edge;begin readln(n); {把图存入邻接矩阵} for i:=1 to n do begin for j:=1 to n do g[i,j]:=maxlongint; end; for i:=1 to n do begin for j:=1 to n do begin read(g[i,j]); end; end; {for i:=1 to n do begin for j:=1 to n do begin write(fo,g[i,j],' '); end; writeln(fo); end;} {建立边集数组,边集数组储存最小生成树用prim算法} {边集数组初始化,从顶点1开始,表示出顶点一到其他各顶点的权} for i:=1 to n-1 do {n各顶点的最小生成树有n-1条边} begin elist[i].prev:=1; elist[i].endv:=i+1; elist[i].weight:=g[1,i+1] end; k:=1;{生成第k边} while k<=n-1 do begin min:=maxlongint; m:=k; for j:=k to n-1 do begin if elist[j].weight<min then begin min:=elist[j].weight; m:=j; end else; end; if m<>k then begin t:=elist[k]; elist[k]:=elist[m]; elist[j]:=t; end else; j:=elist[k].endv;{j为新加入的顶点} {更新已有顶点到剩余其他顶点的最短距离} for i:=k+1 to n-1 do begin if g[j,elist[i].endv]<elist[i].weight then begin elist[i].prev:=j; elist[i].weight:=g[j,elist[i].endv]; end else; end; inc(k); end; tot:=0; for i:=1 to n-1 do begin inc(tot,elist[i].weight); end; writeln(tot); end.
