POJ 3436 ACM computer Factory maximum flow

Source: Internet
Author: User

ACM Computer Factory
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 6121 Accepted: 2126 Special Judge

Description

As you know, all the computers used for ACM contests must is identical, so the participants compete on equal terms. That's why all these computers was historically produced at the same factory.

Every ACM computer consists of P parts. When all these parts was present, the computer is ready and can be shipped to one of the numerous ACM contests.

Computer manufacturing is fully automated by using N various machines. Removes some parts from a half-finished computer and adds some new parts (removing of parts are sometimes nece Ssary as the parts cannot is added to a computer in arbitrary order). Each machine was 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 being able to operat E on it. The specification is a set of P numbers 0, 1 or 2 (one number to each part), where 0 means that corresponding PA RT must not being present, 1-the part was required, 2-presence of the part doesn ' t matter.

Output specification describes the result of the operation, and is a set of P numbers 0 or 1, where 0 means that The part was absent, 1-the part is present.

The machines connected by very fast production lines so, delivery time is negligibly small compared to production Time.

After many years of operation the overall performance of the ACM computer Factory became insufficient for satisfying the G Rowing contest needs. That's 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 FA Ctory machines. It was noted that the easiest-to upgrade the factory are to rearrange production lines. ACM Directorate decided to entrust and solving this problem.

Input

Input file contains integers P n, then n descriptions of the machines. The description of ith machine was represented as by 2 P + 1 integers Qi Si, 1 Si, 2... si, P di, 1 Di, 2 ... Di, P, where Qi specifies performance, Si, J -input Specification for part J, Di, k -output specification for part K.

Constraints

1 ≤ P ≤ 10, 1≤ N ≤ 50, 1≤ Qi ≤10000

Output

Output the maximum possible overall performance, then M -number of connections that must is made, then M descriptions of the connections. Each connection between machines a andB must is described by three positive numbers A B W, wher E W is the number of computers delivered from A to B per 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  0 1 2  1  1 0 2 1 1 1
   
    sample Input 23   0 0 0  0 1 0100 0 1 0 1 0 0 1 0 1 1 1 0 1 1  1 0300 1 1 2  1 1 1
    Sample input 32 2100  0 0  1 0200  0 1  1 1
   

Sample Output

Sample Output 13 3sample Output 24, 3 5, 2, 4, 5 1Sample output 30 0

Hint

Bold texts appearing in the sample sections is informative and does not form part of the actual data.


Test instructions is said that there are n machines, each machine has 2*p+1 parameter values, the first indicates the maximum capacity of the machine, is the maximum number of machinable parts, then the p parameters, input conditions control, and then the P parameters to indicate the output situation. In the input section there are three kinds of numbers, 0,1,2, indicating to be able to feed the parts of the current machine processing p parts of the requirements, 0 said this part must not have, 1 means that the part must have, 2 means that the position is optional. For the output section, only two states are 0 and 1. 0 means there is no part at the output of this position, and 1 indicates that there is a part at this position output. At the end of the output, only if the output part P is 1, it is completed.

Then want to form an assembly line, that is, the product from one machine, and then from another machine in, to meet the condition is that the output of the previous machine must meet the input of the latter machine. So how to be satisfied, because 2 comparison can be considered as 0 or 1 when necessary, so you can ignore it. Then for 0 and 1,00, 11 of the time must be satisfied, but for 01 or 10 can not be satisfied. As a result, the two machines cannot connect to each other as long as the corresponding position in the previous P-bit of the previous machine is equal to 1. Let all connected machines be connected in a single graph, and the topic requires a maximum number of products to be processed at a time and the path of the largest stream can be output.


#include <stdio.h> #include <iostream> #include <string> #include <cstring> #include < algorithm> #include <queue> #define N 109#define INF 99999999using namespace std;int cap[n][n];//max capacity int Flow[n]    [n];//actual traffic int mp[n][n];//The machine that satisfies the condition is the edge-built int n;int EK (int s,int t) {int pre[n],a[n];    memset (flow,0,sizeof flow);    Pre[s]=-1;    queue<int>q;    int ans=0;        while (1) {memset (a,0,sizeof a);        A[s]=inf;        Q.push (s);            while (!q.empty ()) {int V=q.front (); Q.pop ();                    for (int i=1;i<n;i++) {if (a[i]==0 && cap[v][i]>flow[v][i]) {                    A[i]=min (A[v],cap[v][i]-flow[v][i]);                    Pre[i]=v;                Q.push (i);        }}//if (A[t]) break;       } if (a[t]==0) break;           for (int i=pre[t],j=t;i!=-1;j=i,i=pre[i]) {flow[i][j]+=a[t];       FLOW[J][I]-=A[T];  }     ANS+=A[T]; } return ans;    int main () {int p;       int s,t;//source point and sink point while (~scanf ("%d%d", &p,&n)) {s=0;t=n+1;           for (int i=0;i<2*p+1;i++)//Initialize source point and sink point {mp[0][i]=0;       Mp[n+1][i]=1;       } for (int i=1;i<=n;i++) for (int j=0;j<2*p+1;j++) {scanf ("%d", &mp[i][j]);       } n+=2;       memset (cap,0,sizeof cap);               for (int i=0;i<n;i++) {for (int j=0;j<n;j++) {if (i==j) continue;               int flag=0;                       for (int k=1;k<=p;k++) {if (mp[i][k+p]+mp[j][k]==1)//output and input and equal to 1 do not conform to {                   Flag=1;break;               }} if (flag==1) continue;               if (i==0) cap[i][j]=mp[j][0];               else if (j==n-1) cap[i][j]=mp[i][0]; else Cap[i][j] + = min (mp[i][0],mp[j][0]); Note that there must be more than one stream and, plus equals}} printf ("%d", EK(0,n-1));       int cnt=0;       for (int i=1;i<n-1;i++) for (int j=1;j<n-1;j++) if (flow[i][j]>0) cnt++;       cout<<cnt<<endl; for (int i=1;i<n-1;i++) for (int j=1;j<n-1;j++) if (flow[i][j]>0) printf ("%d%d%d\n", i,j,flow[i][    J]); } return 0;}










Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

POJ 3436 ACM computer Factory maximum flow

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.