3408: [Usaco2009 Oct]Heat Wave 热浪

时间:2021-09-08 10:00:36

3408: [Usaco2009 Oct]Heat Wave 热浪

Time Limit: 3 Sec  Memory Limit: 128 MB
Submit: 67  Solved: 55
[Submit][Status][Discuss]

Description

3408: [Usaco2009 Oct]Heat Wave 热浪

Input

 第1行:4个由空格隔开的整数T,C,Ts,Te.
 第2到第C+1行:第i+l行描述第i条道路.有3个由空格隔开的整数Rs,Re,Ci.

Output

    一个单独的整数表示Ts到Te的最小费用.数据保证至少存在一条道路.

Sample Input

7 11 5 4
2 4 2
1 4 3
7 2 2
3 4 3
5 7 5
7 3 3
6 1 1
6 3 4
2 4 3
5 6 3
7 2 1

Sample Output

7

HINT

Source

Gold

题解:话说USACO金组为啥时候冒出来这么多普及组题= =

最短路模板题不解释

 /**************************************************************
Problem:
User: HansBug
Language: Pascal
Result: Accepted
Time: ms
Memory: kb
****************************************************************/ type
point=^node;
node=record
g,w:longint;
next:point;
end;
var
i,j,k,l,m,n,s,t,f,r:longint;
a:array[..] of point;
c,g:array[..] of longint;
d:array[..] of longint;
p:point;
procedure add(x,y,z:longint);
var p:point;
begin
new(p);p^.g:=y;p^.w:=z;
p^.next:=a[x];a[x]:=p;
end;
begin
readln(n,m,s,t);
for i:= to n do a[i]:=nil;
for i:= to m do
begin
readln(j,k,l);
add(j,k,l);add(k,j,l);
end;
fillchar(g,sizeof(g),);
fillchar(c,sizeof(c),);
f:=;r:=;d[]:=s;c[s]:=;g[s]:=;
while f<r do
begin
p:=a[d[f]];
while p<>nil do
begin
if (c[p^.g]=) or ((c[p^.g]>) and (c[p^.g]>(c[d[f]]+p^.w))) then
begin
c[p^.g]:=c[d[f]]+p^.w;
if g[p^.g]= then
begin
g[p^.g]:=;
d[r]:=p^.g;
inc(r);
end;
end;
p:=p^.next;
end;
g[d[f]]:=;
inc(f);
end;
for i:= to n do dec(c[i]);
writeln(c[t]);
readln;
end.