提交日期: 2009-7-28 9:37:00
有效耗时: 796毫秒
测试结果1: 通过本测试点|有效耗时125ms
测试结果2: 通过本测试点|有效耗时46ms
测试结果3: 测试结果错误.错误结果为:18
正确结果应为:4455
测试结果4: 通过本测试点|有效耗时47ms
测试结果5: 通过本测试点|有效耗时93ms
测试结果6: 通过本测试点|有效耗时78ms
测试结果7: 通过本测试点|有效耗时94ms
测试结果8: 通过本测试点|有效耗时94ms
测试结果9: 通过本测试点|有效耗时110ms
测试结果10: 通过本测试点|有效耗时109ms
幸好LS的回答也很牛!
以下是我的程序(仅供参考!):
program li;
var n,p,ans:longint;
a:array[0..101,0..100] of longint;
f:array[0..101] of boolean;
procedure init;
var x,y,i:longint;
begin
readln(n,p);
for i:=2 to n do
begin
read(x,y);
readln(a[x,y]); a[y,x]:=a[x,y];
end;
f[0]:=false; ans:=0;
for i:=1 to n do f[i]:=true;
end;
procedure digui(x:longint);
var i,j,min,xx:longint;
begin
if x=p then begin writeln(ans); halt; end;
min:=maxlongint; xx:=-1;
for i:=1 to n do
if (a[x,i]<min) and (a[x,i]<>0) and (f[i]) then
begin xx:=i; min:=a[x,i]; end;
if xx<>-1 then
begin f[xx]:=false; ans:=ans+a[x,xx]; digui(xx); end;
ans:=ans+a[x,xx];
if xx<>-1 then digui(x);
end;
begin
init;
digui(0);
end.