Bzoj 1934: [Shoi2007]vote vote of good intentions min cut

Source: Internet
Author: User

1934: [Shoi2007]vote vote of goodwill

Time Limit:1 Sec

Memory limit:256 MB

Topic Connection http://www.lydsy.com/JudgeOnline/problem.php?id=1934
Description

There are n children in the kindergarten who are going to vote to decide whether to sleep or not. To them, the problem is not very important, so they decided to carry forward the spirit of humility. Although everyone has their own ideas, but in order to take care of their friends of the idea, they can also vote and their own will be contrary to the vote. We define the number of conflicts in a poll as the total number of conflicts between good friends plus the number of people who have clashed with their own intentions. Our question is, how should each child vote in order to minimize the number of conflicts?

The first line of input is only two integers n,m, guaranteed to have 2≤n≤300,1≤m≤n (n-1)/2. where n represents the total number of people, M is the logarithm of good friends. The second line of the file has n integers, and the first integer represents the will of the child I, and when it is 1, it expresses its consent to sleep, while it is 0 when it stands against sleep. The next file also has m lines, each with two integer i,j. Indicates that I,j is a good friend and we guarantee that no two pairs of i,j will repeat output

You only need to output an integer, which is the smallest possible number of collisions

Sample Input

3 3
1 0 0
1 2
1 3
3 2

Sample Output1hint

Test instructions

Exercises

Minimum network flow Cut

s even agreed, t even disagree with the

Then friends connect with each other

Code:

#include <cstdio>#include<cstring>#include<queue>#include<cmath>using namespacestd;Const intNi =100210; Const intMAX =1<< -; structedge{intU,v,c; intNext;} edge[ -*Ni]; intn,m;intEdn//Number of sides intP[ni];//Father intD[ni];intSP,TP;//origin Point, meeting point voidAddedge (intUintVintc) {edge[edn].u=u; Edge[edn].v=v; Edge[edn].c=C; Edge[edn].next=p[u]; p[u]=edn++; EDGE[EDN].U=v; Edge[edn].v=u; Edge[edn].c=0; Edge[edn].next=P[V]; p[v]=edn++; } intBFs () {Queue<int>Q; memset (d,-1,sizeof(d)); D[SP]=0;     Q.push (SP);  while(!Q.empty ()) {         intCur=Q.front ();         Q.pop ();  for(inti=p[cur];i!=-1; i=Edge[i].next) {             intu=edge[i].v; if(d[u]==-1&& edge[i].c>0) {D[u]=d[cur]+1;             Q.push (U); }         }     }     returnD[TP]! =-1; } intDfsintAintb) {intR=0; if(A==TP)returnFB;  for(inti=p[a];i!=-1&& r<b;i=Edge[i].next) {         intu=edge[i].v; if(edge[i].c>0&& d[u]==d[a]+1)         {             intX=min (edge[i].c,b-R); X=DFS (U,X); R+=x; EDGE[I].C-=x; Edge[i^1].c+=x; }     }     if(!r) d[a]=-2; returnR;} intDinic (intSpintTP) {     intTotal=0, T;  while(BFS ()) { while(t=DFS (Sp,max)) Total+=T; }     returnTotal ;} intMain () {intI,u,v,c;  while(~SCANF ("%d%d",&n,&m)) {edn=0;//Initializememset (p,-1,sizeof(p)); SP=0; tp=n+1;  for(intI=1; i<=n;i++)         {             intx; scanf ("%d",&x); if(x) Addedge (Sp,i,1); ElseAddedge (I,TP,1); }          for(intI=1; i<=m;i++)         {             intx, y; scanf ("%d%d",&x,&y); Addedge (x, Y,1); Addedge (Y,x,1); } printf ("%d\n", Dinic (SP,TP)); }     return 0; }

Bzoj 1934: [Shoi2007]vote vote of good intentions min cut

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.