Link:
#include <stdio.h>int main(){ puts("转载请注明出处[vmurder]谢谢"); puts("网址:blog.csdn.net/vmurder/article/details/44922137");}
Exercises
...... Two times the shortest path and then determine which sides can be on a certain path, and then add to the network flow diagram.
Then the test instructions is a point after the traffic is limited, the disassembly is good.
Then there is the heavy side qwq (adjusted for a long time ...) )
Then there may be self-loops, but that doesn't affect anything.
Code:
The code style has been dog-like during debugging.
See long long i;i<=n;i++ I want to cry
#include <queue>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define N -#define M 201000#define INF 0X3F3F3F3F3F3F3F3FLLusing namespace STD;Long Long MapN [N];Long Longf[2][n];BOOLV[n];Long LongNvoidDij (Long LongSBOOLP) {memset(V,0,sizeofV);memset(F[p],0x3f,sizeofF[P]); f[p][s]=0; for(Long LongI=1; i<n;i++) {Long Longt=inf,x=0; for(Long Longj=1; j<=n;j++)if(!v[j]&&f[p][j]<t) T=f[p][j],x=j;if(!x) Break; v[x]=1; for(Long Longj=1; j<=n;j++)if(!v[j]) f[p][j]=min (f[p][j],f[p][x]+Map[x] [j]); }}structeli{Long LongV,next;Long LongLen;} E[M];Long Longhead[n],cnt;inline voidAddLong LongULong LongVLong LongLen) {e[++cnt].v=v; E[cnt].len=len; E[cnt].next=head[u]; head[u]=cnt;} Queue<long long>QLong LongD[n];BOOLBFS () {memset(d,0,sizeofD); while(!q.empty ()) Q.pop (); Q.push (1), d[1]=1;Long LongI,u,v; while(!q.empty ()) {U=q.front (), Q.pop (); for(I=head[u];i;i=e[i].next) {if(!d[v=e[i].v]&&e[i].len) {d[v]=d[u]+1;if(v==n)return 1; Q.push (v); } } }return 0;}Long LongDinic (Long LongXLong LongFlow) {if(x==n)returnFlowLong LongRemain=flow,k;Long LongI,v; for(I=head[x];i&&remain;i=e[i].next) {if(d[v=e[i].v]==d[x]+1&&e[i].len) {k=dinic (V,min (Remain,e[i].len));if(!k) d[v]=0; e[i].len-=k,e[i^1].len+=k; Remain-=k; } }returnFlow-remain;}Long LongFlow[n],maxflow;voidBuild () {Long LongI,j,k,m;Cin>>n>>m;memset(Map,0x3f,sizeof Map); while(m--) {Cin>>i>>j>>k;MapI [j]=Map[j] [I]=min (MapI [J],k]; } DIJ (1,0), Dij (N,1); for(i=1; i<=n;i++)Cin>>flow[i]; flow[1]=flow[n]=inf; for(cnt=i=1; i<=n;i++) {Add (i*2-1, i*2, Flow[i]), add (i*2, i*2-1,0); for(j=1; j<=n;j++)if(MapI [J]<inf]if(f[0][i]+MapI [j]+f[1][j]==f[0][n])if(i!=j) Add (i*2, j*2-1, INF), add (j*2-1, i*2,0); } n<<=1;}intMain () {//Freopen ("Network1.in", "R", stdin);Build (); while(BFS ())) Maxflow+=dinic (1, INF);cout<<maxflow<<endl; Fclose (stdin); Fclose (stdout);return 0;}
"BZOJ3931" "CQOI2015" network throughput shortest circuit + network flow