Poj3436 ACM computer factory split point + maximum network flow

Source: Internet
Author: User
I have not understood the meaning of this question. After reading the explanation, I understand that there is a factory with multiple computer assembly lines. Each line has a maximum computer capacity, then there are 2 P values corresponding to the input and output respectively. 0 indicates no, 1 indicates yes, and 2 indicates no. Finally, we need to find the maximum number of assemblies, the number of connections to the line, and output the scheme. A computer is assembled only when the output is all 1. Here we need to split a line into two vertices I And I + N, and connect an arc between the two points. The capacity is the maximum capacity of the corresponding computer, if the input does not have 1, then the I + is connected to the source node capacity INF. If the output is all 1, the I + N is connected to the sink node capacity INF. Then, if the output of I matches the input of J, I + N is connected to J with the capacity of INF. Finally, find the maximum stream. Search for the remaining networks. ACM computer factory
Time limit:1000 ms   Memory limit:65536 K
Total submissions:4073   Accepted:1363   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 set
P
Numbers 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
Entrust you with solving this problem.

Input

Input file contains IntegersP n, ThenNDescriptions of the machines. The descriptionITh machine is represented as by 2
P+ 1 IntegersQi Si, 1Si, 2...Si,PDi, 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 machines
AAndBMust be described by three positive numbersA B W, WhereWIs the number of computers delivered from
AToBPer hour.

If several solutions exist, output any of them.

Sample Input

 
Sample input 13 415 0 0 0 0 1 010 0 0 0 1 130 0 1 1 1 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 1 2 1 1 1Sample input 32 2100 0 0 1 0200 0 1 1 1

Sample output

  sample output 1  25 21 3 152 3 10  sample output 2  4 51 3 33 5 31 2 12 4 14 5 1  sample output 3  0 0 
# Include <iostream> # include <cstdio> using namespace STD; # define maxn 200 # define INF 0 xffffffstruct edge {int to, C, next;} e [99999]; struct edge2 {int U, V, F;} EE [99999]; int PI [15] [maxn], po [15] [maxn]; int que [1000], dis [maxn], pre [maxn]; int head [maxn], head2 [maxn]; int St, Ed, maxflow; int en; int N, P; void add (int A, int B, int c) {e [En]. to = B; E [En]. C = C; E [En]. next = head [a]; head [a] = EN ++; E [En]. to = A; E [En]. C = 0; E [En]. next = He AD [B]; head [B] = EN ++;} bool BFS () {memset (DIS,-1, sizeof (DIS); que [0] = ST, dis [st] = 1; int T = 1, F = 0; while (F <t) {Int J = que [f ++]; for (int K = head [J]; k! =-1; k = E [K]. next) {int I = E [K]. to; If (DIS [I] =-1 & E [K]. c) {que [t ++] = I; DIS [I] = dis [J] + 1; if (I = ed) return true ;}}} return false;} int Update () {int P, flow = inf; For (INT I = pre [ed]; I! =-1; I = pre [I]) if (E [head2 [I]. c <flow) P = I, flow = E [head2 [I]. c; For (INT I = pre [ed]; I! =-1; I = pre [I]) E [head2 [I]. c-= flow, E [head2 [I] ^ 1]. c + = flow; maxflow + = flow; return P;} void DFS () {memset (PRE,-1, sizeof (pre); memcpy (head2, Head, sizeof (head2); For (INT I = ST, J; I! =-1;) {int flag = false; For (int K = head [I]; k! =-1; k = E [K]. next) if (E [K]. C & (DIS [J = E [K]. to] = dis [I] + 1) {pre [J] = I; head2 [I] = K; I = J; flag = true; if (I = ed) I = Update (); If (FLAG) break;} If (! Flag) dis [I] =-1, I = pre [I] ;}} void solve () {bool flag = true; int temp; ST = 0, ed = N * 2 + 1; en = 0; maxflow = 0; memset (Head,-1, sizeof (head); For (INT I = 1; I <= N; I ++) {scanf ("% d", & temp); add (I, I + N, temp); flag = true; for (Int J = 1; j <= P; j ++) {scanf ("% d", & PI [I] [J]); if (PI [I] [J] = 1) Flag = false;} If (FLAG) add (St, I, INF); flag = true; for (Int J = 1; j <= P; j ++) {scanf ("% d", & po [I] [J]); If (! Po [I] [J]) Flag = false;} If (FLAG) add (I + N, Ed, INF) ;}for (INT I = 1; I <= N; I ++) {for (Int J = 1; j <= N; j ++) {flag = true; if (I = J) continue; for (int K = 1; k <= P; k ++) {If (po [I] [k] = 1 & PI [J] [k] = 0) Flag = false; if (po [I] [k] = 0 & PI [J] [k] = 1) Flag = false; If (! Flag) break;} If (FLAG) add (I + N, J, INF) ;}} while (BFS () DFS (); int counts = 0; for (INT I = 1; I <= N; I ++) {for (Int J = head [I + N]; J! =-1; j = E [J]. next) {If (E [J]. to = I | E [J]. to = ed) continue; If (E [J ^ 1]. c) {EE [counts]. U = I; EE [counts]. V = E [J]. to; EE [counts ++]. F = E [J ^ 1]. c ;}} printf ("% d \ n", maxflow, counts); For (INT I = 0; I <counts; I ++) printf ("% d \ n", ee [I]. u, ee [I]. v, ee [I]. f);} int main () {While (scanf ("% d", & P, & N )! = EOF) solve (); Return 0 ;}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.