标签:
题解:话说USACO金组为啥时候冒出来这么多普及组题= =
最短路模板题不解释
1 /************************************************************** 2 Problem: 3408 3 User: HansBug 4 Language: Pascal 5 Result: Accepted 6 Time:48 ms 7 Memory:5496 kb 8 ****************************************************************/ 9 10 type 11 point=^node; 12 node=record 13 g,w:longint; 14 next:point; 15 end; 16 var 17 i,j,k,l,m,n,s,t,f,r:longint; 18 a:array[0..100000] of point; 19 c,g:array[0..100000] of longint; 20 d:array[0..1000000] of longint; 21 p:point; 22 procedure add(x,y,z:longint); 23 var p:point; 24 begin 25 new(p);p^.g:=y;p^.w:=z; 26 p^.next:=a[x];a[x]:=p; 27 end; 28 begin 29 readln(n,m,s,t); 30 for i:=1 to n do a[i]:=nil; 31 for i:=1 to m do 32 begin 33 readln(j,k,l); 34 add(j,k,l);add(k,j,l); 35 end; 36 fillchar(g,sizeof(g),0); 37 fillchar(c,sizeof(c),0); 38 f:=1;r:=2;d[1]:=s;c[s]:=1;g[s]:=1; 39 while f<r do 40 begin 41 p:=a[d[f]]; 42 while p<>nil do 43 begin 44 if (c[p^.g]=0) or ((c[p^.g]>0) and (c[p^.g]>(c[d[f]]+p^.w))) then 45 begin 46 c[p^.g]:=c[d[f]]+p^.w; 47 if g[p^.g]=0 then 48 begin 49 g[p^.g]:=1; 50 d[r]:=p^.g; 51 inc(r); 52 end; 53 end; 54 p:=p^.next; 55 end; 56 g[d[f]]:=0; 57 inc(f); 58 end; 59 for i:=1 to n do dec(c[i]); 60 writeln(c[t]); 61 readln; 62 end.
3408: [Usaco2009 Oct]Heat Wave 热浪
标签:
原文地址:http://www.cnblogs.com/HansBug/p/4418567.html