Http://poj.org/problem? Id = 3436
 
 
 
  
   
   | ACM computer factory  
      
       
       | Time limit:1000 ms |  | Memory limit:65536 K |   
       | Total submissions:5286 |  | Accepted:1813 |  | Special Judge |  Description As you know, all the computers used for ACM contests must be identical, so the participates in compete on equal terms. That is why all these computers are historically produced at the same factory. Every ACM computer consists of P parts. When all these parts are present, the computer is ready and can be shipped to one of the numerous ACM contests. Computer Manufacturing is fully automated by usingNVarious machines. each machine removes some parts from a half-finished computer and adds some new parts (removing of parts is sometimes necessary as the parts cannot be added to a computer in arbitrary order ). each machine is described by its performance (measured in computers per hour), input and output specification. Input specification describes which parts must be present in a half-finished computer for the machine to be able to operate on it. The specification is a setPNumbers 0, 1 or 2 (one number for each part), where 0 means that corresponding part must not be present, 1-the part is required, 2-presence of the part doesn' t matter. Output specification describes the result of the operation, and is a setPNumbers 0 or 1, where 0 means that the part is absent, 1-the part is present. The machines are connected by very fast production lines so that delivery time is negligibly small compared to production time. After your years of operation the overall performance of the ACM computer factory became insufficient for satisfying the growing contest needs. That is why ACM directorate decided to upgrade the factory. As different machines were installed in different time periods, they were often not optimally connected to the existing factory machines. it was noted that the easiest way to upgrade the factory is to rearrange production lines. ACM directorate decided to entrust you with solving this problem. Input Input file contains IntegersP n, ThenNDescriptions of the machines. The descriptionITh machine is represented as by 2P+ 1 IntegersQi Si, 1Si, 2...Si,P Di, 1Di, 2...Di,P, WhereQiSpecifies performance,Si,J-Input specification for PartJ,Di,K-Output specification for PartK. Constraints 1 ≤P≤ 10, 1 ≤N≤ 50, 1 ≤Qi≤ 10000 Output Output the maximum possible overall performance, thenM-Number of connections that must be made, thenMDescriptions of the connections. Each connection between machinesAAndBMust be described by three positive numbersA B W, WhereWIs the number of computers delivered fromAToBPer hour. If several solutions exist, output any of them. Sample Input Sample input 13 415  0 0 0  0 1 010  0 0 0  0 1 130  0 1 2  1 1 13   0 2 1  1 1 1Sample input 23 55   0 0 0  0 1 0100 0 1 0  1 0 13   0 1 0  1 1 01   1 0 1  1 1 0300 1 1 2  1 1 1Sample input 32 2100  0 0  1 0200  0 1  1 1 Sample output Sample output 125 21 3 152 3 10Sample output 24 51 3 33 5 31 2 12 4 14 5 1Sample output 30 0 HintBold texts appearing in the sample sections are Ive ive and do not form part of the actual data. SourceNortheastern Europe 2005, far-Eastern subregion | 
 
  
 
 
 
 
Question:
 
N computers are installed on the assembly line, and P components are installed on the computer. Each machine has three parameters: output, input, and output; in the input specification, "0" indicates that no part can be changed; "1" indicates that no part is required; "2" indicates that no part is changed in the output Specification; and "1" indicates that no part is changed. Ask how to arrange pipelines (how to build edges) to maximize output.
 
Analysis:
 
This is the largest stream in the network.
 
Split points first. Because there is a capacity limit on the points, the Split points are connected to one edge, and the capacity is the output;
 
If there is no 1 in the input specification, it is connected to the super source, and the capacity is infinite;
 
If there is no 0 in the output specification, it is connected to the super sink and the capacity is infinite;
 
Determine whether it matches the input and output of other machines. If it can match, the edge is created and the capacity is infinite;
 
Run the maximum stream once on the graph. An edge set with a capacity greater than zero is the solution.
 
 
 
# Include <cstdio> # include <iostream> # include <cstdlib> # include <algorithm> # include <ctime> # include <cctype> # include <cmath> # include <string> # include <cstring> # include <stack> # include <queue> # include <list> # include <vector> # include <map> # include <set> # define sqr (x) (x) * (x) # define ll long # define ITN int # define INF 0x3f3f3f3f # define PI 3.1415926535897932384626 # define EPS 1e-10 # define maxm 210007 # define maxn 1 07 using namespace STD; int FIR [maxn]; int U [maxm], V [maxm], Cap [maxm], flow [maxm], NEX [maxm]; int e_max; int LV [maxn], Q [maxn], ITER [maxn]; void add_edge (INT _ u, int _ v, int _ w) {int e; E = e_max ++; U [e] = _ u; V [e] = _ v; CAP [e] = _ w; nex [e] = FIR [U [e]; FIR [U [e] = E; E = e_max ++; U [e] = _ V; V [e] = _ u; CAP [e] = 0; NEX [e] = FIR [U [e]; FIR [U [e] = E ;} void dinic_bfs (INT s) {int F, R; memset (LV,-1, sizeof LV); LV [s] = 0; Q [f = r = 0] = s; while (F <= r) {I NT x = Q [f ++]; for (int e = FIR [X]; ~ E; E = NEX [e]) {If (Cap [e]> flow [e] & LV [V [e] <0) {LV [V [e] = lv [U [e] + 1; Q [++ R] = V [e] ;}}} int dinic_dfs (INT _ u, int T, int _ f) {If (_ u = T) return _ F; For (Int & E = ITER [_ u]; ~ E; E = NEX [e]) {If (Cap [e]> flow [e] & LV [U [e] <LV [V [e]) {int _ d = dinic_dfs (V [e], T, min (_ F, Cap [e]-flow [e]); If (_ d> 0) {flow [e] + = _ d; flow [E ^ 1]-= _ d; return _ d ;}} return 0 ;}int max_flow (INT s, int t) {memset (flow, 0, sizeof flow); int total_flow = 0; For (;) {dinic_bfs (s); If (LV [T] <0) return total_flow; memcpy (ITER, fir, sizeof fir); int _ F; while (_ f = dinic_dfs (S, T, INF)> 0) total_flow + = _ F;} return Tal_flow;} struct node {int in [10], out [10]; int in1, out0;} A [55]; int main () {# ifndef online_judge freopen ("/home/fcbruce/documentation/code/T", "r", stdin); # endif // online_judge int P, N, S, T, _ w; e_max = 0; memset (FIR,-1, sizeof fir); scanf ("% d", & P, & N); s = 0; t = n + 1; for (INT I = 1; I <= N; I ++) {scanf ("% d", & _ w ); add_edge (I, I + N, _ w); A [I]. in1 = 0; For (Int J = 0; j <p; j ++) {scanf ("% d", & A [I]. in [J]); if (a [I]. in [J] = 1) A [I]. I N1 ++;} A [I]. out0 = 0; For (Int J = 0; j <p; j ++) {scanf ("% d", & A [I]. out [J]); if (a [I]. out [J] = 0) A [I]. out0 ++;} if (a [I]. in1 = 0) add_edge (S, I, INF); if (a [I]. out0 = 0) add_edge (I + N, T, INF); For (Int J = 1; j <I; j ++) {if (a [J]. in1! = 0 & A [I]. out0! = 0) {bool flag = true; For (int K = 0; flag & K <p; k ++) {if (a [I]. out [k] + A [J]. in [k] = 1) Flag = false;} If (FLAG) add_edge (I + N, J, INF);} if (a [I]. in1! = 0 & A [J]. out0! = 0) {bool flag = true; For (int K = 0; flag & K <p; k ++) {if (a [J]. out [k] + A [I]. in [k] = 1) Flag = false;} If (FLAG) add_edge (J + N, I, INF) ;}} printf ("% d ", max_flow (S, T); int m = 0; For (int e = 0; e <e_max; e ++) {If (flow [e] <= 0 | U [e] = S | V [e] = T | V [e]-U [e] = = N) continue; U [m] = U [e]> n? U [e]-N: U [E]; V [m] = V [E]; flow [m] = flow [E]; m ++ ;} printf ("% d \ n", m); For (int e = 0; e <m; e ++) printf ("% d \ n ", U [e], V [e], flow [e]); Return 0 ;}