"BZOJ2127" happiness min cut their own yy out of Jiantu,

Source: Internet
Author: User

Reprint Please specify source:http://blog.csdn.net/vmurder/article/details/42609669

In fact, I just feel that the original traffic is a bit more uncomfortable than unauthorized piracy 233 ...


That's not to say the cost flow is the minimum cut.

Think about it and make sure the smallest cut.


Considering a person, the arts and sciences can not be combined, may wish to build a point, and then to the source (arts), meeting Point (science) with the edge, flow (that is, cut) is the corresponding Joy value. (Here the idea is to build a similar, there are loopholes and then, Ah, build auxiliary points ah what)


And then consider the value of a mutual joy between friends:

If you choose the text, then you need to cut off the joy of both the choice of the value,

If you are all chosen, then you need to cut down the joy value of both of the selected texts,

If a article is a reason, then it is all cut.


First of all, for a point pair, we consider that the relationship between them only depends on the choice of the text or the joy value of the selection,

And for the smallest cut we have to cut this part of the weight, then we can build the edges and then handle the edges.


One

First of all, I started with the idea of setting the weight of the side to both the selected text + the same as the chosen one.

This has succeeded in satisfying the situation of one article and one rationale.

But it can't be separated.


Two

At this point we can put the edge into place, and then the people on both sides to this point even the non-edge of the capacity INF,

Then the source point (liberal arts) to this point to choose the capacity of the text, meeting point connected to the selected reason.

In this way we are satisfied with the choice of the text or the choice of the case.

That is to say, we can not cut "all choose the text" This weight value, all choose the same reason.

But this is WA's, and cheat is not (measured), because we can not let the two people one-to-one reason.


Three

To the "one" there, we find that we sometimes need to cut both weights.

This time to think:

A-(LEN)-->b, when Len value is certain, the figure is built a-->b-->c-->d, as long as the side length is Len, then the minimum cut is unchanged.


So we split the "edge" into two points, a corresponding s set (text), a corresponding T-set (RB),

So we can change the original INF to the corresponding weights, so that the cut which edge is the minimum cut value.

That might be a little vague, so let's take a picture.


This map is built, so you can understand why simply by analyzing it.

Post code:

#include <queue> #include <cstdio> #include <cstring> #include <iostream> #include < algorithm> #define N 50005#define M 300000#define P 105#define inf 0x3f3f3f3fusing namespace std;struct ksd{int V,len,ne XT;} E[m];int head[n],cnt;inline void Add (int u,int v,int len) {e[++cnt].v=v;e[cnt].len=len;e[cnt].next=head[u];head[u]= cnt;e[++cnt].v=u;e[cnt].len=len;e[cnt].next=head[v];head[v]=cnt;} int S,t,d[n];queue<int>q;bool BFS () {while (!q.empty ()) Q.pop () memset (d,0,sizeof (d)); int I,u,v;q.push (s), D[s] =1;while (!q.empty ()) {U=q.front (), Q.pop (); for (I=head[u];i;i=e[i].next) {v=e[i].v;if (!d[v]&&e[i].len) {D[v ]=d[u]+1;if (v==t) return 1;q.push (v);}} return 0;} int dinic (int x,int flow) {if (x==t) return flow;int remain=flow,i,v,k;for (i=head[x];i&&remain;i=e[i].next) {v= E[i].v;if (D[v]==d[x]+1&&e[i].len) {k=dinic (V,min (Remain,e[i].len)), if (!k) d[v]=0;e[i].len-=k,e[i^1].len+ =k;remain-=k;}} return flow-remain;} int N,m,id[p][p];int sum,maxflow;void Build () {int i,j,a,TEMP;SCANF ("%d%d", &n,&m), temp=n*m;s=n*m+2* (n-1) *m+2*n* (m-1) +1,t=n*m+2* (n-1) *m+2*n* (m-1) +2;for (i=1;i <=n;i++) for (j=1;j<=m;j++) id[i][j]=++cnt;cnt=1;//the first matrix is n rows m column the number in column J of this matrix indicates the value of joy earned by the students who choose the Humanities in column I, Row J. for (i=1;i<=n;i++) for (j=1;j<=m;j++) {scanf ("%d", &a); Sum+=a;add (s,id[i][j],a);} The second matrix is n rows m column the number in column J of this matrix indicates the joy value that the classmate of the seat in column J of Row I has chosen for science. for (i=1;i<=n;i++) for (j=1;j<=m;j++) {scanf ("%d", &a); Sum+=a;add (id[i][j],t,a);} The third matrix is n-1 row m column the number in column J of this matrix indicates the additional joy value obtained by the students in row J of section I and the students of section J of Row I+1. for (i=1;i<n;i++) for (j=1;j<=m;j++) {scanf ("%d", &a), Sum+=a,++temp;add (Id[i][j],temp,a), add (Id[i+1][j], TEMP,A); add (s,temp,a);} The fourth matrix is a n-1 row m column the number in column J of this matrix indicates the additional joy value obtained by the students in column J of row I and the students of section J of Row I+1. for (i=1;i<n;i++) for (j=1;j<=m;j++) {scanf ("%d", &a), Sum+=a,++temp;add (Id[i][j],temp,a), add (Id[i+1][j], TEMP,A); add (temp,t,a);} The fifth matrix is n rows m-1 columns column I of row J of this matrix indicates that the students in column J of row I, and the students of row I of section j+1, choose the additional joy value obtained by the Liberal Arts. for (i=1;i<=n;i++) for (j=1;j<m;j++) {scanf ("%d", &a); Sum+=a,++temp;add (Id[i][j],temp,A), add (id[i][j+1],temp,a); add (s,temp,a);} The sixth matrix is n rows m-1 columns column I of row J of this matrix indicates the additional joy value obtained by the students of the seat in column J of row I and the classmates in row I of section j+1. for (i=1;i<=n;i++) for (j=1;j<m;j++) {scanf ("%d", &a), Sum+=a,++temp;add (Id[i][j],temp,a), add (Id[i][j+1], TEMP,A); add (temp,t,a);}} int main () {//freopen ("test.in", "R", stdin), build (), while (BFS ()) maxflow+=dinic (S,inf);p rintf ("%d\n", Sum-maxflow); return 0;}



"BZOJ2127" happiness min cut their own yy out of Jiantu,

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.