/* The upper and lower bounds of a source sink can be used to find a feasible stream. A source sink can be converted to a non-Source Sink: add an edge t ~ S (0, 0x7fffffff) is the basic process of creating an additional network (add the necessary arc for the new source sink separation) find the maximum flow of the additional network. If the adjacent edge of the new source is full, a feasible flow exists. Question: there is a table, given the sum of each row and the sum of each column and the requirements of some elements, find a qualified table with a more detailed explanation of partition (one end must be a new source or sink, only when the stream is full can there be a feasible stream. At this time, there are two types (New Source SS sin TT): 1. adding (u, v) traffic is the difference between the upper and lower bounds (SS, V) and (u, TT) traffic is the lower bound traffic. It can be understood as follows: (u, v) the difference between the upstream and downstream traffic is because (SS, v) Traffic whose lower bound traffic is 0 is the lower bound traffic because the lower bound traffic in (u, v) needs to be supplemented, direct traffic to V (u, TT) is the flow of lower-bound traffic from the previous U, and cannot pass all (u, v ). The article above will talk about this side directly to TT, But he uses the second one when writing it. add (u, v) traffic to the upper and lower bounds (SS, u) and (u, TT) the traffic is the sum of all lower-bound flows into U minus all lower-bound flows from U (shown in the figure) the two methods separate the lower bound of an edge or vertex from the edge vertex, so that the lower bound of all edges or vertices is 0, the lower bound part of the maximum flow problem is directly provided by the SS or directly routed to TT */# include <iostream> # include <string> using namespace STD; # define n 235int map [N] [N], M, N, S, T, X, Y, up [N] [N], low [N] [N], yu [N], num [N], d [N]; int min (int A, int B) {return a <B? A: B;} int max (int A, int B) {return A> B? A: B;} void INI () {memset (low, 0, sizeof (low); memset (MAP, 0, sizeof (MAP); memset (Yu, 0, sizeof (Yu); For (INT I = 0; I <= m; ++ I) for (Int J = 0; j <= N; ++ J) up [I] [J] = 0x7fffff;} int build () {for (INT I = 1; I <= m; I ++) for (Int J = 1; j <= N; j ++) if (low [I] [J]> up [I] [J]) return 0; else {Yu [I]-= low [I] [J], Yu [J + M] + = low [I] [J]; // here m is written as NMAP [I] [J + M] = up [I] [J]-low [I] [J];} return 1 ;} int SAP (int u, int f) {If (u = y) // return F; int V, mind = Y, last = F, cost; // mind = point-1 if it starts from 0, that is, the last point for (V = 0; v <= y; ++ V) {If (Map [u] [v]> 0) {If (d [u] = d [v] + 1) {cost = SAP (v, min (last, map [u] [v]); map [u] [v]-= cost; Map [v] [u] + = cost; last-= cost; if (d [x]> = Y + 1) return F-last; If (last = 0) break;} If (d [v] <mind) mind = d [v] ;}}if (last = f) {-- num [d [u]; If (Num [d [u] = 0) d [x] = Y + 1; d [u] = mind + 1; ++ num [d [u];} return F-last;} void limitflow () // {int I, j, c = 0; // The maximum traffic of the C stream x = t + 1, y = T + 2; // new source sinks for (I = s; I <= T; ++ I) if (Yu [I]> 0) map [x] [I] = Yu [I]; // necessary arc else if (Yu [I] <0) map [I] [Y] =-Yu [I]; // necessary arc map [T] [s] = 0x7fffffff; // change the source image to a passive memset (D, 0, sizeof (d); memset (Num, 0, sizeof (Num); For (Num [x] = Y + 1; d [x] <Y + 1;) // y + 1 point C + = SAP (x, 0x7fffff); // use sap to find the maximum stream for (I = s; I <= T; ++ I) // determines whether the stream is full. If (Map [x] [I]) {cout <"impossible" <Endl; return;} for (I = 1; I <= m; ++ I) // output feasible stream {for (j = 1; j <n; ++ J) cout <(up [I] [J]-map [I] [J + M]) <""; // upper bound-cout of unused cout values <(up [I] [N]-map [I] [n + M]) <Endl ;}cout <Endl ;} int main () {int cas, sum1, sum2, I, j, A, B, num, C, F1, F2, T1, T2; string op; CIN> CAS; while (CAS --) {CIN> m> N; S = 0, T = m + n + 1, sum1 = sum2 = 0; INI (); for (I = 1; I <= m; ++ I) CIN> A, Yu [s]-= A, Yu [I] + =, sum1 + = A; For (; I <= m + n; ++ I) CIN> A, Yu [I]-= A, Yu [T] + =, sum2 + = A; CIN> C; while (c --) // The processing method is good {CIN> A> B> OP> num; f1 = t1 = A; F2 = t2 = B; if (a = 0) F1 = 1, T1 = m; If (B = 0) F2 = 1, t2 = N; for (I = F1; I <= T1; ++ I) for (j = F2; j <= t2; ++ J) if (OP [0] = ') low [I] [J] = max (Num, low [I] [J]), up [I] [J] = min (Num, up [I] [J]); else if (OP [0] = '> ') low [I] [J] = max (Num + 1, low [I] [J]); else if (OP [0] = '<') up [I] [J] = min (num-1, up [I] [J]);} If (sum1 = sum2 & build () limitflow (); else cout <"impossible" <Endl;} return 0 ;}