Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

怎么一直Runtime Error?

Posted by 19921020 at 2009-06-21 20:49:40 on Problem 1258 and last updated at 2009-06-21 20:51:44
绝对标准的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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator