Description Kindergarten There are N children planning to vote to decide whether to sleep or nap. 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 requires only one integer, which is the smallest possible number of collisions. Sample Input3 3
1 0 0
1 2
1 3
3 2
Sample Output1HINT
In the first example, all the children voted for the best solution.
When you do it, you get a board, you think about it. For everyone, if he agrees on a capacity of 1 on the side, to t even a capacity of 0 side, against the opposite is good friends of the children with each other, the capacity is 1, to find the smallest cut, Is the answer because each person is either agree, or oppose, can only choose one, choose to go against their own will pay the price, that is the flow ...
1#include <cstdio>2#include <cstring>3#include <cmath>4#include <iostream>5 using namespacestd;6 Const intinf=100000000, n=310;7 structee{intTo,next,f;} e[n*n*2];8 inthead[n],q[n*2],dis[n],x[n];9 intS,t,n,m,cnt=1, ans,w;Ten One voidInsintUintVintf) { Ae[++cnt].to=v;e[cnt].f=f;e[cnt].next=head[u];head[u]=CNT; -e[++cnt].to=u;e[cnt].f=0; e[cnt].next=head[v];head[v]=CNT; - } the - BOOLBFs () { - for(intI=1; i<=t;i++) dis[i]=inf; - intH=0, t=1, now; +q[1]=s;dis[s]=0; - while(h!=t) { +now=q[++h]; A for(intI=head[now];i;i=E[i].next) { at intv=e[i].to; - if(e[i].f&&dis[now]+1<Dis[v]) { -dis[v]=dis[now]+1; - if(v==t)return 1; -q[++t]=v; - } in } - } to if(Dis[t]==inf)return 0;return 1; + } - the intDinic (intNowintf) { * if(now==t)returnF; $ intrest=F;Panax Notoginseng for(intI=head[now];i;i=E[i].next) { - intv=e[i].to; the if(e[i].f&&dis[v]==dis[now]+1&&rest) { + intt=dinic (V,min (REST,E[I].F)); A if(!t) dis[v]=0; thee[i].f-=T; +e[i^1].f+=T; -rest-=T; $ //if (t) printf ("%d%d%d\n", now,v,e[i].f); $ } - } - returnF-rest; the } - intMain () {Wuyiscanf"%d%d",&n,&m); thes=0, t=n+1; - for(intI=1; i<=n;i++) { Wuscanf"%d",&x[i]); - if(x[i]==0) Ins (S,i,1), Ins (I,t,0); About ElseIns (S,i,0), Ins (I,t,1); $ } - intu,v; - for(intI=1; i<=m;i++){ -scanf"%d%d",&u,&v); AIns (U,v,1); Ins (V,u,1); + } the while(BFS ()) ans+=dinic (s,inf); -printf"%d", ans); $}
"Bzoj 1934" [Shoi2007]vote vote of goodwill