记录编号 |
49095 |
评测结果 |
WWWWW |
题目名称 |
最难的任务 |
最终得分 |
0 |
用户昵称 |
FrCsKOH |
是否通过 |
未通过 |
代码语言 |
Pascal |
运行时间 |
0.077 s |
提交时间 |
2012-11-07 12:45:31 |
内存使用 |
0.47 MiB |
显示代码纯文本
program C1254;
const Be=20000;
Bf=200;
var e,next:array[1..Be] of longint;
head,dist:array[1..Bf] of longint;
v:array[1..Bf] of boolean;
q:array[1..Bf*5] of longint;
S:array[1..Bf,1..Bf] of longint;
n,a,b,l,m,i,T,j:longint;
function Spfa(v0,vN:longint):longint;
var i,t,h:longint;
begin
fillchar(v,sizeof(v),false);
for i:=1 to n do dist[i]:=maxlongint;
h:=0;
t:=1;
q[t]:=v0;
v[v0]:=true;
dist[v0]:=0;
while h<>t do begin
inc(h);
i:=head[q[h]];
v[q[h]]:=false;
while i<>0 do begin
if (S[q[h],e[i]]<>0) and (dist[e[i]]>dist[q[h]]+S[q[h],e[i]]) then begin
dist[e[i]]:=dist[q[h]]+S[q[h],e[i]];
if not v[e[i]] then begin
v[e[i]]:=true;
inc(t);
q[t]:=e[i];
end;
end;
i:=next[i];
end;
end;
Spfa:=dist[vN];
end;
begin
assign(input,'hardest.in');
reset(input);
assign(output,'hardest.out');
rewrite(output);
readln(T);
for j:=1 to T do begin
fillchar(S,sizeof(S),0);
readln(n,m);
for i:=1 to m do begin
readln(a,b,l);
if S[a,b]<>0 then begin
e[i<<1-1]:=b;
next[i<<1-1]:=head[a];
head[a]:=i<<1-1;
e[i<<1]:=a;
next[i<<1]:=head[b];
head[b]:=i<<1;
S[a,b]:=l;
S[b,a]:=l;
end;
end;
writeln(Spfa(1,n));
end;
close(input);
close(output);
end.