输入边数与矩阵
program agrinet;
var
n,i,j,minj:integer;
mark:array[1..100] of boolean;
map:array[1..100,1..100] of longint;
dist:array[1..100] of longint;
min,ans:longint;
begin
ans:=0;
readln(n);
for i:=1 to n do
for j:=1 to n do
read(map[i,j]);
for i:=1 to n do dist[i]:=maxlongint;
dist[1]:=0;
mark[1]:=true;
minj:=1;
for i:=1 to n-1 do begin
for j:=1 to n do
if dist[j]>map[minj,j] then begin dist[j]:=map[minj,j]; end;
min:=maxlongint;
for j:=1 to n do
if (dist[j]<min) and (not mark[j]) then begin
minj:=j;
min:=dist[j];
end;
mark[minj]:=true;
inc(ans,min);
end;
writeln(ans);
end.
posted on 2005-08-18 20:31
李青 阅读(1172)
评论(0) 编辑 收藏 引用