Acdream 1017 Fast Transportation

Source: Internet
Author: User

http://acdream.info/problem?pid=1017

Test instructions: Give n points, M edge, K goods, from S to T, every day each side can only pass 1 times, begging for a few days to finish

Idea: Split the composition layer diagram, each layer down a layer of edge, note I can also connect to I, the flow is INF, represents this point of the van this day did not move

1#include <cstdio>2#include <iostream>3#include <cmath>4#include <algorithm>5#include <cstring>6 #defineINF 0x7fffffff7 structedge{8     intu,v;9}e[200005];Ten inttot,go[500005],next[500005],first[500005],op[500005],flow[500005],dis[500005],cnt[500005]; One intt,s,ss,tt,n,m,nodes,k; A intid[ the][ the]; - intRead () { -     intt=0, f=1;CharCh=GetChar (); the      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} -      while('0'<=ch&&ch<='9') {t=t*Ten+ch-'0'; ch=GetChar ();} -     returnt*F; - } + voidInsertintXintYintz) { -tot++; +go[tot]=y; Anext[tot]=First[x]; atfirst[x]=tot; -flow[tot]=Z; - } - voidAddintXintYintz) { -Insert (x, y, z); op[tot]=tot+1; -Insert (Y,x,0); op[tot]=tot-1; in } - intDfsintXintf) { to     if(x==t)returnF; +     intmn=nodes,sum=0; -      for(intI=first[x];i;i=Next[i]) { the          intPur=Go[i]; *          if(flow[i]&&dis[pur]+1==Dis[x]) { $              intSave=dfs (Pur,std::min (flow[i],f-sum));Panax Notoginsengflow[i]-=Save; -flow[op[i]]+=Save; thesum+=Save; +              if(dis[s]>=nodes| | F==sum)returnsum; A          } the          if(Flow[i]) mn=std::min (Mn,dis[pur]); +     } -     if(sum==0){ $cnt[dis[x]]--; $         if(cnt[dis[x]]==0){ -dis[s]=nodes; -}Else{ thedis[x]=mn+1; -cnt[dis[x]]++;Wuyi         } the     } -     returnsum; Wu } - BOOLCheckintmid) { About      for(intI=0; i<=nodes;i++) first[i]=cnt[i]=dis[i]=0; tot=0; $     intsz=0; -      for(intI=1; i<=mid;i++) -          for(intj=1; j<=n;j++) -id[i][j]=++sz; At=sz+1; +sz+=2; thes=0; nodes=sz; -Add (s,id[1][ss],k); $      for(intI=1; i<=mid;i++) the Add (id[i][tt],t,k); the      for(intI=1; i<mid;i++) the       for(intj=1; j<=n;j++) theAdd (id[i][j],id[i+1][j],inf);  -      for(intI=1; i<=m;i++) in          for(intj=1; j<mid;j++) theAdd (id[j][e[i].u],id[j+1][E[I].V],1), Add (id[j][e[i].v],id[j+1][E[I].U],1); the     intans=0; About      while(Dis[s]<nodes) ans+=DFS (s,inf); the     returnans==J;  the } the intMain () { +      while(SCANF ("%d", &n)! =EOF) { -M=read (); K=read (); Ss=read (); tt=read (); the           for(intI=1; i<=m;i++)BayiE[i].u=read (), e[i].v=read (); the          intL=1, r=n+k+2, ans=0; the           while(l<=R) { -             intMid= (L+R)/2; -             if(Check (mid)) r=mid-1, ans=mid; the                 ElseL=mid+1; the           } theprintf"%d\n", ans-1); the     } -}

Acdream 1017 Fast Transportation

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.