Test instructions: Give a n*m matrix of each row and each column and, there are some lattice restrictions, to find a set of legitimate programs.
The source points to the row, the sink point to the column, and an edge that is both upper and lower bound.
For a restriction of a lattice, the edge of its upper and lower bounds from the row to which it is located.
The feasible flow of the upper and lower bounds of Yuanhui can be obtained.
The concrete method can transfer from the meeting point to the source point to the positive infinity edge, and turn into the feasible flow without Yuanhui and upper bounds.
You can then create a new super Yuanhui, for an edge with a lower bound of l, an upper bound of R (x, y), an edge with a capacity of L for the super sink from the super source point to the Y,x, and X to Y with a capacity of R-l edge.
If those sides with a capacity of L are not full flow, then there is no solution.
#include <cstdio>#include<cstring>#include<algorithm>#include<queue>using namespacestd;Const intINF =0x3f3f3f3f, N = the, M =25000;Charop[2];intQ,n,m,c,x,y,z,s,t,s,t,e=1, fr,l[205][ -],r[205][ -],ans[205][ -],hd[n],nxt[m],to[m],f[m],ch[n];voidAddintXintYintz) {to[++e] = y, f[e] = Z, nxt[e] = hd[x], hd[x] =e; to[++e] = x, f[e] =0, nxt[e] = Hd[y], hd[y] =e;}voidUpdintXinty) {if(op[0] =='<') R[x][y] = min (r[x][y], Z1); Else if(op[0] =='>') L[x][y] = max (L[x][y], z+1); ElseL[x][y] = max (l[x][y], z), r[x][y] =min (r[x][y], z);}BOOLTel () {memset (ch,-1,sizeofch); Queue<int>Q; Q.push (S), Ch[s]=0; while(!Q.empty ()) { intU =Q.front (); Q.pop (); for(inti = Hd[u]; I i = Nxt[i])if(Ch[to[i]] = =-1&& F[i]) ch[to[i] = ch[u]+1, Q.push (To[i]); } returnCH[T]! =-1;}intZng (intAintb) {if(A = = T)returnb; intR =0; for(inti = Hd[a]; I && b > r; i = Nxt[i])if(Ch[to[i]] = = ch[a]+1&&F[i]) { intrr = Zng (To[i], min (b-R, F[i])); F[i]-= RR, f[i^1] + = RR, r + =RR; } if(!r) Ch[a] =-1; returnR;}intMain () {scanf ("%d", &q); while(q--) {e=1; memset (HD,0,sizeofHD); memset (L,0,sizeofl); Memset (R,0x3f,sizeofR); scanf ("%d%d", &n, &m), t = n+m+1, S = n+m+2, T = n+m+3, add (T,s,inf); for(inti =1; I <= N; i++) scanf ("%d", &x), add (s,i,x), add (s,t,x); for(inti =1; I <= m; i++) scanf ("%d", &x), add (s,t,x), add (i+n,t,x); scanf ("%d", &c); while(c--) {scanf ("%d%d%s%d", &x, &y, OP, &z); if(!x &&!)y) { for(inti =1; I <= N; i++) for(intj =1; J <= M; J + +) upd (I,J); } Else if(!x) { for(inti =1; I <= N; i++) upd (i,y); } Else if(!y) { for(inti =1; I <= m; i++) upd (x,i); } Elseupd (x, y); } if(FR) Puts (""); Fr=1; for(inti =1; I <= N; i++) for(intj =1; J <= M; J + +) { if(R[i][j] < l[i][j]) {Puts ("Impossible");GotoAA;} Add (I,j+N,R[I][J]-L[I][J]), add (s,j+N,l[i][j]), add (I,t,l[i][j]); } while(tel ()) while(Zng (S,inf)); for(inti = Hd[s]; I i = Nxt[i])if(F[i]) {Puts ("Impossible");GotoAA;} for(inti =1; I <= N; i++) for(intj = Hd[i]; J j =Nxt[j])if(To[j] > N && to[j] <= n+m) ans[i][to[j]-n] = f[j^1]; for(inti =1; I <= N; i++) for(intj =1; J <= M; J + +) printf ("%d%c", Ans[i][j]+l[i][j],"\ n"[j==m]); AA:; } return 0;}
feasible flow with Yuanhui upper and lower bounds (POJ2396)