level 2
lolloveu
楼主
var i,j,n,m,sum,k,l,min,x,y,e:longint;
cost:array [1..10000,1..10000] of longint;
mincost,closed:array [1..1000] of longint;
begin
readln(n,e);
for i:=1 to n do
for j:=1 to n do
cost[i,j]:=maxlongint;
for j:=1 to e do
begin
read(x,y,l);
if l<cost[x,y] then
begin
cost[x,y]:=l;
cost[y,x]:=l;
end;
end;
for i:=1 to n do
for j:=1 to n do
if (i=j) and (cost[i,j]=maxlongint) then
cost[i,j]:=0;
for i:=1 to n do
begin
mincost[i]:=cost[1,i];
closed[i]:=1;
end;
sum:=0;
for i:=2 to n do
begin
min:=maxlongint;
for j:=1 to n do
if (mincost[j]<=min) and (mincost[j]<>0) then
begin
min:=mincost[j];
k:=j;
end;
inc(sum,min);
mincost[k]:=0;
for j:=1 to n do
if (mincost[j]>=cost[k,j]) and (mincost[j]<>0) then
begin
mincost[j]:=cost[k,j];
closed[j]:=k;
end;
end;
writeln(sum);
end.
then
begin
mincost[j]:=cost[k,j];
closed[j]:=k;
end;
end;
writeln(sum);
end.
第四个测试点错了
2012年03月31日 13点03分
1
cost:array [1..10000,1..10000] of longint;
mincost,closed:array [1..1000] of longint;
begin
readln(n,e);
for i:=1 to n do
for j:=1 to n do
cost[i,j]:=maxlongint;
for j:=1 to e do
begin
read(x,y,l);
if l<cost[x,y] then
begin
cost[x,y]:=l;
cost[y,x]:=l;
end;
end;
for i:=1 to n do
for j:=1 to n do
if (i=j) and (cost[i,j]=maxlongint) then
cost[i,j]:=0;
for i:=1 to n do
begin
mincost[i]:=cost[1,i];
closed[i]:=1;
end;
sum:=0;
for i:=2 to n do
begin
min:=maxlongint;
for j:=1 to n do
if (mincost[j]<=min) and (mincost[j]<>0) then
begin
min:=mincost[j];
k:=j;
end;
inc(sum,min);
mincost[k]:=0;
for j:=1 to n do
if (mincost[j]>=cost[k,j]) and (mincost[j]<>0) then
begin
mincost[j]:=cost[k,j];
closed[j]:=k;
end;
end;
writeln(sum);
end.
then
begin
mincost[j]:=cost[k,j];
closed[j]:=k;
end;
end;
writeln(sum);
end.
第四个测试点错了