P1179: [APIO2009]ATM

Source: Internet
Author: User

Pinch point +SPFA Shortest path, because there is no ring, so direct SPFA.

1 ConstMaxe=1000001;2 type3Node=Record4 F,t:longint;5 end;6 varN,m,s,i,j,ans,cnt,num,u,x,dgr:longint;7h,he,dfn,low,q,d,v,va,bl:array[0.. Maxe] of Longint;8b,bi:array[0.. Maxe] of node;9f:array[0.. maxe* -] of Longint;Tenp:array[0.. Maxe] of Boolean; One function min (a,b:longint): Longint; A begin -   ifA>b then exit (b)Elseexit (a); - end; the procedure Insert (u,v:longint); - begin -With Bi[i] Do - begin +f:=He[u]; -t:=v; + end; Ahe[u]:=i; at end; - procedure Reinsert (u,v:longint); - begin - Inc (CNT); -With B[CNT] Do - begin inf:=H[u]; -t:=v; to end; +h[u]:=CNT; - end; the procedure Readd; * varI,e,v:longint; $ beginPanax Notoginsengcnt:=0; -    fori:=1to n Do the begin +e:=He[i]; A        whileE<>0  Do the begin +v:=bi[e].t; -           ifBl[i]<>Bl[v] Then reinsert (Bl[i],bl[v]); $e:=bi[e].f; $ end; - end; - end; the procedure Tarjan (x:longint); - varE,t,j:longint;Wuyi begin the Inc (DGR); Inc (NUM); -p[x]:=true; F[num]:=x; DFN[X]:=DGR; low[x]:=dgr; Wue:=He[x]; -    whileE<>0  Do About begin $t:=bi[e].t; -       ifdfn[t]=0 Then - begin - Tarjan (t); A           ifLow[x]>low[t] Then low[x]:=Low[t]; + End the       Else if(P[t]) and (Dfn[t]<low[x]) then low[x]:=Dfn[t]; -e:=bi[e].f; $ end; the   ifdfn[x]=Low[x] Then the begin thej:=0; Inc (CNT); the        whileJ<>x Do - begin inj:=F[num]; the Dec (num); thep[j]:=false; Aboutbl[j]:=CNT; the           //Writeln (J, ", CNT); the Inc (V[cnt],va[j]); the end; + end; - end; the procedure SPFA;Bayi varE,t,now,l,r:longint; the begin theFillchar (P,sizeof(p),true); -Fillchar (D,sizeof(d),0); -l:=1; r:=1; f[1]:=bl[s]; p[bl[s]]:=false; D[bl[s]]:=v[bl[s]];//Writeln (V[bl[s]); the    whileL<=r Do the begin thenow:=F[l]; thee:=H[now]; -        whileE<>0  Do the begin thet:=b[e].t; the           //if T=1 then Writeln (' X ', now, ', v[t]);94           ifd[t]<d[now]+V[t] Then the begin thed[t]:=d[now]+V[t]; the               ifP[t] Then98 begin Aboutp[t]:=false; - Inc (R);101f[r]:=T;102 end;103 end;104e:=b[e].f; the end;106 Inc (L);107p[now]:=true;108 end;109 end; the begin111 readln (n,m); the    fori:=1to M Do113 begin the readln (u,x); the Insert (u,x); the end;117    fori:=1to n Doreadln (Va[i]);118Fillchar (P,sizeof(p),false);119    fori:=1to n Do ifdfn[i]=0Then Tarjan (i); - readln (s,m);121 Readd;122   //For i:=1 to 4 do Writeln (V[i]);123 SPFA;124    fori:=1to M Do the begin126 read (u);127       ifD[bl[u]]>ans then ans:=D[bl[u]]; - end;129 writeln (ans); theEnd.
View Code

(Reproduced Please specify Source: http://www.cnblogs.com/Kalenda/)

P1179: [APIO2009]ATM

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.