Poj3436 ACM Computer Factory, maximum stream, output path

Source: Internet
Author: User

Poj3436 ACM Computer Factory, maximum stream, output path
POJ 3436 ACM Computer Factory

Computer companies have N computers, each of which generates Qi in a unit of time.


A computer consists of P parts. Each machine can only work on a semi-finished computer with some parts (or an empty computer with nothing) it turns into a semi-finished computer or a complete computer with other parts (or some parts may be removed ). Ask the computer company for the maximum unit time output, and which machines have a cooperative relationship, that is, the machines on which one machine delivers its products for processing.


Sample input
3 4
15 0 0 0 0 1 0
10 0 0 0 0 1 1
30 0 1 2 1 1 1
3 0 2 1 1 1 1

Sample output
25 2
1 3 15
2 3 10

Input: The computer consists of three parts. There are 4 machines in total. The output of machine 1 is 15. You can add Part 2 to the empty computer, machine 2 can add Part 2 and Part 3 to an empty computer, machine 3 can turn a computer with both Part 2 and Part 3 into a finished product (each part has one)


Output: the maximum output per unit time is 25. Two machines have a cooperative relationship,
Machine 1 needs to process 15 computers to machine 3 within the unit time
Machine 2 needs to process 10 computers to machine 3 within the unit time



The data size is small. You can use EdmondsKarp. The main question is not only the maximum flow value, but also the edge with flow.

Think about it carefully. You don't need to split this question!


#include
 
  #include
  
   #include#include
   
    #include
    
     using namespace std;typedef long long LL;const int maxn = 60;const int inf = 0x7fffffff;struct Edge {    int from,to,cap,flow;    Edge(int u,int v,int c,int f):from(u),to(v),cap(c),flow(f) {}};struct EdmondsKarp {    int n,m;    vector
     
       edges;    vector
      
        G[maxn]; int p[maxn]; int a[maxn]; void init(int n) { this->n=n; for(int i=0; i
       
         Q; Q.push(s); a[s]=inf; while(!Q.empty()) { int x=Q.front(); Q.pop(); for(int i=0; i
        
         e.flow) { a[e.to]=min(a[x],e.cap-e.flow); p[e.to]=G[x][i]; Q.push(e.to); if(e.to==t) break; } } if(a[t])break; } if(!a[t])break; for(int u=t; u!=s; u=edges[p[u]].from) { edges[p[u]].flow+=a[t]; edges[p[u]^1].flow-=a[t]; } flow+=a[t]; } return flow; }};EdmondsKarp solver;int P, N;int w[maxn], in[maxn][12], out[maxn][12];int print[maxn][5], cnt;int main(){ int i, j; bool flag; while(~scanf("%d%d", &P, &N)) { int s = 0, t = N+1; solver.init(N+2); for(int i=1; i<=N; ++i) { scanf("%d", &w[i]); flag = true; for(j=0; j
         
          0 && e.to != t && e.from != s) { print[cnt][0] = e.from; print[cnt][1] = e.to; print[cnt++][2] = e.flow; } } printf("%d\n", cnt); for(i=0; i
          
           

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.