Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
怎么一直Runtime Error?绝对标准的prim啊~谁帮忙看下!! program p1258; const maxn=100; var n:integer; cost:array[1..maxn,1..maxn] of longint; ans:int64; procedure init; //读入 var i,j:integer; begin readln(n); for i:=1 to n do for j:=1 to n do read(cost[i,j]); end; procedure prim(v0:integer); //绝对正确的prim,我2485也是这么做的! var lowcost:array[1..maxn] of longint; i,j,k,min:longint; begin for i:=1 to n do lowcost[i]:=cost[v0,i]; for i:=1 to n-1 do begin min:=maxint; for j:=1 to n do if (lowcost[j]<min) and (lowcost[j]<>0) then begin min:=lowcost[j]; k:=j; end; inc(ans,lowcost[k]); lowcost[k]:=0; for j:=1 to n do if cost[k,j]<lowcost[j] then lowcost[j]:=cost[k,j]; end; writeln(ans); end; begin while not eof do begin init; prim(1); end; end. Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator