| ||||||||||
| 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 | |||||||||
为什么WA?我的思路是把已有的边赋成0,然后Prim.
程序:
var
m:array[1..300,1..300] of longint;
n,t,ans:longint;
procedure init;
var
i,j,a,b:longint;
begin
readln(n);
for i:=1 to n do
begin
for j:=1 to n do read(m[i,j]);
readln;
end;
readln(t);
for i:=1 to n do
for j:=1 to n do
if m[i,j]=0 then m[i,j]:=maxlongint;
for i:=1 to t do
begin
readln(a,b);
m[a,b]:=0;
end;
ans:=0;
end;
procedure prim;
var
l,c:array[1..300] of longint;
mark:array[1..300] of boolean;
i,j,k,min:longint;
begin
for i:=1 to n do
begin
l[i]:=m[1,i];
c[i]:=1;
end;
l[1]:=-1;
for i:=1 to n-1 do
begin
min:=maxlongint;
for j:=1 to n do
if (l[j]<min)and(l[j]<>-1) then
begin
min:=l[j];
k:=j;
end;
ans:=ans+m[c[k],k];
l[k]:=-1;
for j:=1 to n do
if m[k,j]<l[j] then
begin
l[j]:=m[k,j];
c[j]:=k;
end;
end;
end;
procedure print;
begin
writeln(ans);
end;
begin
while not seekeof do
begin
init;
prim;
print;
end;
end.
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator