The topic probably says that a nuclear reactor's cooling system has n nodes, there are M-one-way pipes connecting them, the flow inside the pipe has the requirements of the upper and lower bounds, asking whether the liquid can circulate in the whole system.
In essence is to seek a non-Yuanhui traffic has the upper and lower bounds of the capacity of the network of feasible flow, because no Yuanhui capacity network each vertex to meet the flow balance conditions, that is, all points of ∑ inflow flow =∑ outflow flow , can be seen as the flow inside is a circular flow, similar to the Touau pull loop.
The algorithm of feasible flow in the upper bound is based on the sufficient and necessary condition of a flow in the network flow, which is the limiting condition and equilibrium condition , to transform the original network into a capacity network without the lower bound. The mathematical model of those proofs such as not difficult to understand, see the paper, "a simple method to solve the traffic has upper and lower bounds of the network network flow problem."
And the way of transformation seems to have two very popular, I use the practice is:
- Set D[u] as vertex u out edge lower bound and-in Edge nether and, new source point, sink Point
- The arc <u,v> capacity of the original network is set to its upper bound-the lower bound
- For each vertex u, if the d[u]<0 is the edge of the source point to its capacity-d[u], otherwise its edge to the meeting point D[u]
- Finally, if the arcs associated with the source point are full-flow, there is a feasible flow, and the flow of each edge + its lower bound in the original network is a solution
1#include <cstdio>2#include <cstring>3#include <queue>4#include <algorithm>5 using namespacestd;6 #defineINF (1<<30)7 #defineMAXN 2228 #defineMAXM 222*4449 Ten structedge{ One intV,cap,flow,next; A }EDGE[MAXM]; - intVs,vt,ne,nv; - intHEAD[MAXN]; the - voidAddedge (intUintVintcap) { -Edge[ne].v=v; Edge[ne].cap=cap; edge[ne].flow=0; -Edge[ne].next=head[u]; head[u]=ne++; +Edge[ne].v=u; edge[ne].cap=0; edge[ne].flow=0; -EDGE[NE].NEXT=HEAD[V]; head[v]=ne++; + } A at intLEVEL[MAXN]; - intGAP[MAXN]; - voidBFs () { -memset (level,-1,sizeof(level)); -Memset (Gap,0,sizeof(GAP)); -level[vt]=0; ingap[level[vt]]++; -queue<int>que; to Que.push (VT); + while(!Que.empty ()) { - intu=Que.front (); Que.pop (); the for(intI=head[u]; i!=-1; I=Edge[i].next) { * intv=edge[i].v; $ if(level[v]!=-1)Continue;Panax Notoginsenglevel[v]=level[u]+1; -gap[level[v]]++; the Que.push (v); + } A } the } + - intPRE[MAXN]; $ intCUR[MAXN]; $ intIsap () { - BFS (); -memset (pre,-1,sizeof(pre)); thememcpy (Cur,head,sizeof(head)); - intu=pre[vs]=vs,flow=0, aug=INF;Wuyigap[0]=NV; the while(level[vs]<NV) { - BOOLflag=false; Wu for(int&i=cur[u]; i!=-1; I=Edge[i].next) { - intv=edge[i].v; About if(Edge[i].cap!=edge[i].flow && level[u]==level[v]+1){ $flag=true; -pre[v]=u; -u=v; - //aug= (Aug==-1?edge[i].cap:min (Aug,edge[i].cap)); AAug=min (aug,edge[i].cap-edge[i].flow); + if(v==VT) { theflow+=; - for(u=pre[v]; V!=vs; v=u,u=Pre[u]) { $edge[cur[u]].flow+=; theedge[cur[u]^1].flow-=; the } the //Aug=-1; theaug=INF; - } in Break; the } the } About if(flag)Continue; the intMinlevel=NV; the for(intI=head[u]; i!=-1; I=Edge[i].next) { the intv=edge[i].v; + if(Edge[i].cap!=edge[i].flow && level[v]<minlevel) { -Minlevel=Level[v]; thecur[u]=i;Bayi } the } the if(--gap[level[u]]==0) Break; -level[u]=minlevel+1; -gap[level[u]]++; theu=Pre[u]; the } the returnflow; the } - intLOW[MAXM],D[MAXN]; the intMain () { the intt,n,m,a,b,c; thescanf"%d",&t);94 while(t--){ thescanf"%d%d",&n,&m); thememset (D,0,sizeof(d)); thevs=0; vt=n+1; nv=vt+1; Ne=0;98memset (head,-1,sizeof(head)); About for(intI=0; i<m; ++i) { -scanf"%d%d%d%d",&a,&b,low+i,&c);101Addedge (a,b,c-low[i]);102d[a]+=Low[i];103d[b]-=Low[i];104 } the inttot=0;106 for(intI=1; i<=n; ++i) {107 if(d[i]<0) Addedge (vs,i,-d[i]);108 ElseAddedge (I,vt,d[i]), tot+=D[i];109 } the if(ISAP ()!=tot) puts ("NO");111 Else{ thePuts"YES");113 for(intI=0; i<m; ++i) { theprintf"%d\n",edge[i<<1].flow+low[i]); the } the }117Putchar ('\ n');118 }119 return 0; -}
ZOJ2314 Reactor Cooling (no Yuanhui flow with upper and lower bounds of the network feasible flow)