5 3
1 4 5
4 5 1
1 2 7

10 11
1 2 3
2 3 4
3 4 5
4 5 6
5 6 7
6 7 8
7 8 9
8 9 10
9 10 11
1 5 7
6 9 3

# 样例输出

6

28

=================

========================

type
pnode=^node;
node=record
x,t:longint;
next:pnode;
end;
var
n,m:longint;
ti:array[1..30000]of pnode;
dis:array[1..30000]of longint;
f_bo:array[1..30000]of boolean;
h:array[1..200000]of longint;
procedure init;
begin
assign(input,'rq341.in');
assign(output,'rq341.out');
reset(input); rewrite(output);
end;

procedure terminate;
begin
close(input); close(output);
halt;
end;

procedure insert(x,y,t:longint);
var
p:pnode;
begin
new(p);
p^.t:=t; p^.x:=y;
p^.next:=ti[x]; ti[x]:=p;
end;

procedure spfa;
var
l,r:longint;
x:longint;
p:pnode;
begin
fillchar(dis,sizeof(dis),\$7);
fillchar(f_bo,sizeof(f_bo),true);
dis[1]:=0;
f_bo[1]:=false;
l:=0; r:=1;
h[r]:=1;
repeat
inc(l);
x:=h[l];
p:=ti[x];
while p<>nil do
begin
if dis[x]+p^.t<dis[p^.x] then
begin
dis[p^.x]:=dis[x]+p^.t;
if f_bo[p^.x] then
begin
inc(r);
h[r]:=p^.x;
f_bo[p^.x]:=false;
end;
end;
f_bo[x]:=true;
p:=p^.next;
end;
until l>=r;
writeln(dis[n]);
end;

procedure main;
var
i:longint;
x,y,t:longint;
begin
for i:=1 to n do ti[i]:=nil;
for i:=1 to m do
begin
insert(x,y,t);
insert(y,x,t);
end;
spfa;
end;

begin
init;
main;
terminate;
end.


#### RQNOJ 341 星门跳跃【解题报告】

2016-03-01 09:39:00

#### 深度理解（链式前向星+spfa模板）

2017-08-02 08:24:32

#### SPFA算法及前向星优化

2010-11-21 22:29:00

#### C(最短路_spfa+前向星)

2014-09-01 00:00:48

#### spfa+链式前向星

2016-09-16 20:47:56

#### [HDU 2544] 最短路 spfa写法 + 链式前向星

2016-05-11 10:43:55

#### SPFA优化：SLF，LLL，前向星

2012-09-11 18:25:13

#### Rqnoj341星门跳跃

2012-04-19 22:08:44

#### 【最短路】星门跳跃

2012-11-06 18:34:40

#### 星门跳跃-rqnoj-341

2013-07-03 21:06:52