测评机: Xeond[6]
得分: 90分
提交日期: 2010-8-27 16:13:00
有效耗时: 2406毫秒
测试结果1: 通过本测试点|有效耗时203ms
测试结果2: 通过本测试点|有效耗时156ms
测试结果3: 通过本测试点|有效耗时172ms
测试结果4: 通过本测试点|有效耗时188ms
测试结果5: 通过本测试点|有效耗时234ms
测试结果6: 通过本测试点|有效耗时344ms
测试结果7: 通过本测试点|有效耗时297ms
测试结果8: 通过本测试点|有效耗时250ms
测试结果9: 通过本测试点|有效耗时562ms
测试结果10: 测试结果错误.错误结果为:7554
正确结果应为:8087
程序:
var
i,n,m:longint;
a,b,e:array[0..150000] of longint;
dis,f:array[0..30000] of int64;
procedure quick(s,t:longint);
var
i,j,x,tmp:longint;
begin
i:=s; j:=t; x:=a[(i+j)div 2];
repeat
while a[i]<x do inc(i);
while a[j]>x do dec(j);
if i<=j then
begin
tmp:=a[i]; a[i]:=a[j]; a[j]:=tmp;
tmp:=b[i]; b[i]:=b[j]; b[j]:=tmp;
tmp:=e[i]; e[i]:=e[j]; e[j]:=tmp;
inc(i); dec(j);
end;
until i>=j;
if i<t then quick(i,t);
if s<j then quick(s,j);
end;
procedure spfa(k:longint);
var
v:array[0..30000] of boolean;
que:array[0..30000] of longint;
top,tail,now,i:longint;
begin
fillchar(v,sizeof(v),false);
v[k]:=true; que[1]:=k; top:=0; tail:=1;
for i:=1 to n do dis[i]:=maxlongint;
dis[k]:=0;
repeat
inc(top);
now:=que[(top-1)mod n+1];
for i:=f[now] to f[now+1]-1 do
if dis[now]<>maxlongint then
if dis[b[i]]>dis[now]+e[i] then
begin
dis[b[i]]:=dis[now]+e[i];
if not v[b[i]] then
begin
inc(tail);
que[(tail-1)mod n+1]:=b[i];
v[b[i]]:=true;
end;
end;
v[now]:=false;
until top=tail;
end;
begin
readln(n,m);
for i:=1 to m do readln(a[i],b[i],e[i]);
for i:=m+1 to 2*m do
begin
a[i]:=b[i-m];
b[i]:=a[i-m];
e[i]:=e[i-m];
end;
m:=2*m;
quick(1,m);
for i:=1 to m do
if f[a[i]]=0 then f[a[i]]:=i;
f[n+1]:=m+1;
for i:=n downto 1 do
if f[i]=0 then f[i]:=f[i+1];
spfa(1);
writeln(dis[n]);
end.