Water problem, bare shortest.
Constmaxn=6200001; type link=^node; Node=record t,d:longint; F:link; End;varn,m,s,i,j,u,v,w,max:longint;adj:array[0.. the] of link;f:array[0..1000000] of longint;d,val:array[0.. the] of longint;went:array[0.. the] of boolean;procedure Insert (f,t,d:longint);varP:link;beginNew(P); P^.f:=Adj[f]; P^.t:=T; P^.d:=D; ADJ[F]:=p;end;procedure SPFA (s:longint);varL,r,now,i:longint;p:link;begin fori:=1to n DoD[i]:=MAXN; Fillchar (went,sizeof(went),true); L:=1; r:=1; f[1]:=s; d[s]:=0; went[s]:=false; whileL<=r Dobegin now:=F[l]; P:=Adj[now]; whileP<>nil Dobeginifd[p^.t]>d[now]+p^. D THEN BEGIN d[p^.t]:=d[now]+p^. D; ifwent[p^. t] then begin WENT[P^.t]:=false; Inc (R); F[R]:=p^. T; End End P:=p^. F; End Went[now]:=true; Inc (L); End;end;begin readln (n,m,s); fori:=1to M Dobegin READLN (U,V,W); Insert (U,V,W); //Insert (v,u,w);end; fori:=1to n Do ifI<>s THEN begin SPFA (i); Val[i]:=D[s]; End SPFA (s); fori:=1to n Do ifI<>S THEN BEGIN Inc (Val[i],d[i]); ifVal[i]>max then max:=Val[i]; End Writeln (max); end.
P3408: [Usaco2009 oct]heat wave heat wave