[Network flow 24 questions] space flight planning problem

Source: Internet
Author: User

Description

$W $ professor is planning a series of space flights for the National Space Center. Every space flight can make a series of commercial experiments to gain profits. A selection of experimental collections $e={e_1,e_2,..., e_m}$ has been identified, and the set of all instruments required for these experiments to be used $i={i_1,i_2,..., i_n}$. The instrument to be used in experimental $e_j$ is a subset of the $i$ $r_j\;\in\;i$. The cost of configuring the instrument $i_k$ is $c_k$ USD. The sponsors of the experimental $e_j$ have agreed to pay $p_j$ dollars for the results of the experiment. $W $ The task of the professor is to determine which experiments are to be carried out in a space flight and which instruments are to be configured to make space flight the biggest net yield. The net income here is the difference between the full amount of revenue obtained from the experiment and the total cost of the equipment being configured.

Input

There are $2$ positive integer $m,n$ in line $1$ of the file. $m $ is the number of experiments, $n $ is the number of instruments.

The next $m$ line, each row is an experiment with the relevant data. The first number of sponsors agreed to pay the cost of the experiment, followed by the number of instruments used in the experiment.

The number of $n$ in the last line is the cost of configuring each instrument.

Output

Line $1$ is the experiment number.

Line $2$ is the instrument number.

The last line is net income.

Sample Input

2 3
10 1 2
25 2 3
5 6 7

Sample Output

1 2
1 2 3
17

HINT

$n, m,p_i<50$.

Solution

The most powerful closed sub-graph.

$s $ to the experiment I even a flow of $p_i$ edge,

The experiment $i$ to the instrument $j$ a flow of $+\infty$ edge,

Instrument $i$ to $t$ with a flow of $c_i$ side,

Maximum yield =$\sum_{i=1}^{m}p_i$-minimum cut.

#include <cmath>#include<ctime>#include<queue>#include<stack>#include<cstdio>#include<vector>#include<cstring>#include<cstdlib>#include<iostream>#include<algorithm>#defineN 105#defineM 5205#defineINF 500using namespacestd;structgraph{intnxt,to,f;} E[M];intG[n],c[n],p[n],dep[n],n,m,s,t,sum,cnt=1;BOOLB[n];queue<int>q; inlineBOOLReadint&k) {    intret=0;CharC=GetChar ();  while(!IsDigit (c)) C=GetChar ();  while(IsDigit (c)) {ret= (ret<<1) + (ret<<3) +c-'0'; C=GetChar (); } k=ret; returnc!='\ n';} InlinevoidAddedge (intXintYintf) {e[++cnt].nxt=g[x];g[x]=cnt;e[cnt].to=y;e[cnt].f=F;} InlinevoidAdde (intXintYintf) {Addedge (x,y,f); Addedge (Y,x,0);} InlineBOOLBFsintu) {memset (DEP,0,sizeof(DEP)); Dep[u]=1; Q.push (U);  while(!Q.empty ()) {u=Q.front (); Q.pop ();  for(intI=g[u];i;i=e[i].nxt)if(e[i].f>0&&!Dep[e[i].to])                {Q.push (e[i].to); Dep[e[i].to]=dep[u]+1; }    }    returndep[t];} InlineintDfsintUintf) {    intret=0; if(u==t)returnF;  for(intI=g[u],d;i&&f;i=e[i].nxt)if(e[i].f>0&&dep[e[i].to]>Dep[u]) {D=Dfs (E[i].to,min (F,E[I].F)); E[I].F-=d;e[i^1].f+=d;ret+=d;f-=D; }    returnret;} InlineintDinic () {intret=0;  while(true){        if(!bfs (s))returnret; RET+=DFS (S,inf); }}inlinevoidAireen () {scanf ("%d%d",&m,&N); S=m+n+1; t=s+1;  for(intI=1, k;i<=m;++i) {        if(!read (P[i])) Break;  while(read (k)) Adde (i,k+M,inf); Adde (I,k+M,inf); }     for(intI=1; i<=n;++i) {scanf ("%d", &c[i]); Adde (i+M,t,c[i]); }     for(intI=1; i<=m;++i) {Sum+=P[i];adde (S,i,p[i]); } Sum-=Dinic ();  for(intI=1; i<=m;++i)if(!BFS (i)) {printf ("%d", i);  for(intj=g[i];j;j=e[j].nxt) b[e[j].to-m]=true; } printf ("\ n");  for(intI=1; i<=n;++i)if(B[i]) printf ("%d", i); printf ("\ n"); printf ("%d\n", sum); return;}intMain () {Freopen ("shut.in","R", stdin); Freopen ("Shut.out","W", stdout);    Aireen ();    Fclose (stdin);    Fclose (stdout); return 0;}

[Network flow 24 questions] space flight planning problem

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.