Description After a period of time, the network company finally has a certain popularity, also began to receive some orders, of which the largest one from the city of B. Blue Mary decided to sign the order in person. To save money on travel, one of his financial advisers suggested buying only u airline tickets. U airlines have only one flight per day, and are all arriving in the afternoon on the day of departure, so they can only take one flight per day. After investigation, they were given detailed information on all flights operated by U Airways, which included the departure of each flight, the destination, and the number of votes to be picked up on one day. (Note: For a certain flight, whichever day they are able to buy the most, the number of votes on the day of departure will be the same.) Blue Mary notes that they will be able to reach City B from City a only on a U-airline flight, but they may not be able to reach B city on the same day due to the limited number of tickets that can be purchased on each flight. So now that Blue Mary needs your help, design a travel plan to make the arrival time of the last person arriving in City b the earliest. The first line of input contains 3 positive integers n,m and T. All cities that appear in the title are numbered,..., N, with City a number must be 1, City B must be n. U company has a total of M (one-way) flights. And even Blue Mary, the company has a total of t individual to go from a city to B city. The following m lines, each line containing 3 positive integers, x, y, Z, represent the origin of each flight of the company, the destination and the number of votes that Blue Mary can buy on one day of the flight. (that is, on either day, Blue Mary can only buy tickets for Z-U airlines from City X to City Y.) ) Enter a maximum of one-way flights from one city to another city. Output has only one row and contains a positive integer that represents the earliest arrival time of the person who finally reached City B. Let's say that the day they first took the plane was the first day. Sample INPUT3 3 5
1 2 1
2 3 5
3 1 4
Sample OUTPUT6
HINT
Conventions:
2 <= N <= 50
1 <= M <= 2450
1 <= T <= 50
1 <= x, y <= N
X! = Y
1 <= Z <= 50
Positive solution: Maximum flow.
Maximum stream + bare routines that are split by time.
1#include <bits/stdc++.h>2 #defineIl inline3 #defineRG Register4 #definell Long Long5 #defineN (2000010)6 #defineINF (1<<30)7 8 using namespacestd;9 Ten structedge{intNt,to,flow,cap;} G[n]; One structe{intU,v,w; }e[2500]; A - intid[ the][310],head[n],q[n],d[n],s,t,n,m,t,num,cnt,ans,flow; - theIlintgi () { -Rgintx=0, q=1; RgCharCh=GetChar (); - while((ch<'0'|| Ch>'9') && ch!='-') ch=GetChar (); - if(ch=='-') q=-1, ch=GetChar (); + while(ch>='0'&& ch<='9') x=x*Ten+ch- -, ch=GetChar (); - returnq*x; + } A atIlvoidInsert (RGint fromRgintTo,rgintcap) { -G[++num]= (Edge) {head[ from],to,0, cap},head[ from]=num; -G[++num]= (Edge) {Head[to], from,0,0},head[to]=num;return; - } - -IlintBFS (RGintS,rgintT) { in for(RGintI=1; i<=cnt;++i) d[i]=0; -RgintH=0, t=1; q[t]=s,d[s]=1; to while(h<6) { +Rgintx=q[++h],v; - for(RGintI=head[x];i;i=G[i].nt) { thev=g[i].to; * if(!d[v] && g[i].cap>G[i].flow) { $d[v]=d[x]+1, q[++t]=v;Panax Notoginseng if(v==t)return 1; - } the } + } A returnD[t]; the } + -IlintDFS (RGintX,rgintT,rginta) { $ if(!a | | x==t)returnA Rgintv,f,flow=0; $ for(RGintI=head[x];i;i=G[i].nt) { -v=g[i].to; - if(d[v]==d[x]+1&& g[i].cap>G[i].flow) { theF=dfs (V,t,min (a,g[i].cap-g[i].flow)); - if(!f) {d[v]=-1;Continue; }Wuyig[i].flow+=f,g[i^1].flow-=F; theFlow+=f,a-=f;if(!a)returnflow; - } Wu } - returnflow; About } $ -IlintMaxflow (RGintS,rgintT) { -Rgintflow=0; - while(BFS (s,t)) flow+=DFS (s,t,inf); A returnflow; + } the - intMain () { $ #ifndef Online_judge theFreopen ("bluemary.in","R", stdin); theFreopen ("Bluemary.out","W", stdout); the #endif theN=gi (), M=gi (), T=gi (), num=1, s=++cnt,t=++CNT; - for(RGintI=1; i<=m;++i) E[i].u=gi (), E[i].v=gi (), e[i].w=gi (); in for(RGintI=1; i<=n;++i) id[i][0]=++CNT; theInsert (s,id[1][0],t), insert (id[n][0],t,inf); the while(++ans) { About for(RGintI=1; i<=n;++i) Id[i][ans]=++cnt,insert (id[i][ans-1],id[i][ans],inf); the for(RGintI=1; i<=m;++i) Insert (id[e[i].u][ans-1],ID[E[I].V][ANS],E[I].W); theInsert (Id[n][ans],t,inf), Flow+=maxflow (s,t);if(flow==t) Break; the } +cout<<ans;return 0; -}
bzoj1570 [Jsoi2008]blue Mary's Trip