"The main topic"
Small m in MC opened two huge farmland A and B (you can think the capacity is infinite), now, small p has the seeds of n crops, each crop seed has 1 (that is, can plant a crop) (with 1...N number), now, the first I plant in a planted in a can gain AI benefits, The benefits of BI can be obtained by planting in B, and with the M-crop combinations, the c1i of the crops in the first combination can be obtained by the additional benefits of the c2i in a, together with the additional benefits of the total in B, so small m quickly calculates the maximum yield of the plant. "Thinking" first, if there is no combination of the scheme should be how to do? actually very convenient. First the super source point S and the Super Sink point t,s to each I with a capacity of the AI side, T to each I even a capacity for the side of BI. The obvious answer = total capacity of the sum-minimum cut. So what if there's a combination? For each scheme, we can split into two points U and V, from S to u with a capacity of c1i, and a V to T with a capacity of C2i edge. Then the S to each point in the combination of a capacity of the INF, by each point in the composition to t with a capacity of the INF edge. It is obvious that the cutting edge is bound to be the point of connection with S or T. There may be a doubt here: if the edges of a point in a collection are in a point connected to S, and the u,v cut is in a point connected to T (that is, we planted the crop in a, but the proceeds are in B. In fact, it is--impossible. We can prove that:
the cutting edges in the U, V, and their combinations must also be connected with s or T, otherwise there must be a path of s to T, you can not form a cut! So the last
answer = Sum of total capacity-min cutDraw a picture to understand:)
... T, don't know why.
deleted the STL section. It's still T. I want to be quiet.
/*or tle, look back.*/#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#defineS 0#defineT MAXN-1using namespacestd;Const intinf=0x7fffffff;Const intmaxn= the+ -; Const intmaxm=4004000+ -;structnode{intFr,to,pos,cap;};intn,m,sum;intDIS[MAXN];intVIS[MAXN];intCUR[MAXN];intFirst[maxn],next[maxm];node EDGE[MAXM];inttot=0;intRead () {intx =0; CharCH =GetChar (); while(Ch <'0'||'9'<ch) Ch=GetChar (); while('0'<= CH && Ch <='9') {x= x *Ten+ CH-'0'; CH=GetChar (); } returnx;}voidAddedge (intUintVintc) {edge[++tot]= (node) {u,v,tot+1, C}; Next[tot]=first[u];first[u]=tot; edge[++tot]= (node) {u,v,tot-1,0}; Next[tot]=first[v];first[v]=tot;}voidbuild () {memset (First,-1,sizeof(first)); Memset (Next,-1,sizeof(next)); intAi,bi; N=read (); for(intI=1; i<=n;i++) {AI=read (); Sum+=AI; Addedge (S,i,ai); } for(intI=1; i<=n;i++) {bi=read (); Sum+=i; Addedge (I,T,BI); } m=read (); intk,c1i,c2i; for(intI=1; i<=m;i++) {k=read (); C1i=read (); c2i=read (); intu=n+i; intv=n+i+m; Addedge (s,u,c1i); Addedge (v,t,c2i); Sum+=c1i+c2i; for(intj=1; j<=k;j++) { intCI; CI=read (); Addedge (U,ci,inf); Addedge (Ci,v,inf); } }}intBFs () {memset (DIS,-1,sizeof(DIS)); intL=0, r=0; intQUE[MAXN]; que[++r]=S; Dis[s]=0; while(l<r) {inthead=que[l];l++; for(inti=first[head];i!=-1; i=Next[i]) {Node&tmp=Edge[i]; if(dis[tmp.to]==-1&& tmp.cap>0) {dis[tmp.to]=dis[head]+1; que[++r]=tmp.to; } } } return(dis[t]!=-1);}intDfsintSintTintf) {Vis[s]=1; if(s==t | |!f)returnF; intres=0; for(inti=first[s];i!=-1; i=Next[i]) {Node&tmp=Edge[i]; if(!vis[tmp.to] && tmp.cap>0&& dis[tmp.to]==dis[s]+1) { intDelta=Dfs (Tmp.to,t,min (tmp.cap,f)); if(delta>0) {Tmp.cap-=Delta; Edge[tmp.pos].cap+=Delta; F-=Delta; Res+=Delta; if(!f)returnRes; } } } returnRes;}intDinic () {intflow=0; while(BFS ()) {memset (Vis,0,sizeof(VIS)); Flow+=DFS (S,t,inf); } returnflow;}intMain () {build (); printf ("%d\n", sum-dinic ()); return 0;}
"Maximum weight closure sub-plot/min cut" bzoj3438-small m crop "pending"