P3408: [Usaco2009 oct]heat wave heat wave

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.