Topic links
Given to n individuals, each has a state of 0 or 1. Then M-relationships, if A and B have a relationship, then a, a, a, a, two person's state is different, then a value is generated. Of course a person can also change its state, which also produces a value.
A final state is obtained to minimize the sum of the resulting values and to output the minimum value.
The bare smallest cut, unexpectedly did not see out.
If the state of a person is 1, then the source point is connected to him, and if it is 0, connect to the meeting point. If two people have a relationship, then the two people have an edge, the weight is 1.
And then run the smallest cut you can.
#include <iostream>#include<vector>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<map>#include<Set>#include<string>#include<queue>#include<stack>#include<bitset>using namespacestd;#definePB (x) push_back (x)#definell Long Long#defineMK (x, y) make_pair (x, y)#defineLson L, M, rt<<1#defineMem (a) memset (a, 0, sizeof (a))#defineRson m+1, R, rt<<1|1#defineMem1 (a) memset (a,-1, sizeof (a))#defineMEM2 (a) memset (a, 0x3f, sizeof (a))#defineRep (i, N, a) for (int i = A; i<n; i++)#defineFi first#defineSe Secondtypedef pair<int,int>PLL;Const DoublePI = ACOs (-1.0);Const DoubleEPS = 1e-8;Const intMoD = 1e9+7;Const intINF =1061109567;Const intdir[][2] = { {-1,0}, {1,0}, {0, -1}, {0,1} };Const intMAXN = 2e5+5;intq[maxn*2], head[maxn*2], dis[maxn/Ten], S, T, num;structnode{intto, Nextt, C; Node () {} node (intTo,intNextt,intc): To, Nextt (NEXTT), C (c) {}}E[MAXN*2];voidinit () {num=0; Mem1 (head);}voidAddintUintVintc) {E[num]= Node (v, Head[u], c); Head[u] = num++;}intBFs () {mem (dis); Dis[s]=1; intSt =0, ed =0; Q[ed++] =s; while(st<ed) { intU = q[st++]; for(inti = Head[u]; ~i; i =e[i].nextt) { intv =e[i].to; if(!dis[v]&&e[i].c) {Dis[v]= dis[u]+1; if(v = =t)return 1; Q[ed++] =v; } } } return 0;}intDfsintUintlimit) { if(U = =t) {returnlimit; } intCost =0; for(inti = Head[u]; ~i; i =e[i].nextt) { intv =e[i].to; if(E[i].c&&dis[v] = = dis[u]+1) { intTMP = DFS (V, min (limit-Cost , e[i].c)); if(tmp>0) {e[i].c-=tmp; E[i^1].C + =tmp; Cost+=tmp; if(Cost = =limit) Break; } Else{Dis[v]= -1; } } } returnCost ;}intDinic () {intAns =0; while(BFS ()) {ans+=DFS (s, INF); } returnans;}intMain () {intN, M, a, b, X; CIN>>n>>m; Init (); S=0, t = n+1; for(inti =1; i<=n; i++) {scanf ("%d", &x); if(x) {Add (S, I,1); Add (I, S,0); } Else{Add (i, T,1); Add (t, I,0); } } while(m--) {scanf ("%d%d", &a, &b); Add (A, B,1); Add (b, A,1); } cout<<dinic () <<Endl; return 0;}
Bzoj 1934: [Shoi2007]vote vote of good intentions min cut