Be sure to think of the smallest cut.
The virtual source S has a supporter capacity of 1, the opponent has a virtual meeting point capacity of 1, and the supporter has a capacity of 1 opponents.
Cut two sides of the point, one side is support, one side is against, the number of conflicts is cut (elder brother. Fog).
The minimum number of collisions is the minimum cut.
#include <algorithm>#include<cstdio>#include<cstring>using namespacestd;Const intMAXN = -+Ten;Const intMAXM =100000+Ten;Const intINF =0x3f3f3f3f;intG[maxn],v[maxm],next[maxm],f[maxm],eid=0;intn,m,a[maxn],s,t;intD[MAXN],GAP[MAXN];voidAddedge (intAintBintF) {V[eid]=b; Next[eid]=g[a]; F[eid]=f; g[a]=eid++; V[eid]=a; NEXT[EID]=G[B]; f[eid]=0; g[b]=eid++;}intISAP (intUintflow) { if(u==t)returnflow; intAug,cur=0, mindist=N; for(intI=g[u];~i;i=Next[i])if(d[u]==d[v[i]]+1&& f[i]>0) { in=isap (V[i],min (f[i],flow-cur)); F[i]-=; F[i^1]+=; Cur+=; if(Cur==flow | | d[s] = = N)returncur; } if(cur==0) { if(!--Gap[d[u]]) {D[s]=N; returncur; } for(intI=g[u];~i;i=next[i])if(F[i]) mindist=min (Mindist,d[v[i]]); ++gap[d[u]=mindist+1]; } returncur;}voidsolve () {gap[0]=N; intres=0; while(d[s]<n) res+=ISAP (S,inf); printf ("%d\n", res);}intMain () {scanf ("%d%d",&n,&m); S=n+1; t=n+2; Memset (g,-1,sizeof(g)); for(intI=1; i<=n;i++) {scanf ("%d",&A[i]); if(a[i]==1) Addedge (S,i,1); ElseAddedge (I,t,1); } N=n+2; for(intI=1, u,v;i<=m;i++) {scanf ("%d%d",&u,&v); if(a[u]!=A[v]) { if(a[u]==1) Addedge (U,v,1); ElseAddedge (V,u,1); }} solve (); return 0;}
bzoj1934: [Shoi2007]vote vote of goodwill