传送门

考虑源点为同意,汇点为反对,那么只要源点向同意的连边,不同意的向汇点连边,求个最小割就是答案

然后考虑朋友之间怎么办,我们令朋友之间连双向边。这样不管怎么割都能对应一种选择情况。那么还是求一个最小割就行了

 //minamoto
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#define inf 0x3f3f3f3f
using namespace std;
#define getc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
char buf[<<],*p1=buf,*p2=buf;
inline int read(){
#define num ch-'0'
char ch;bool flag=;int res;
while(!isdigit(ch=getc()))
(ch=='-')&&(flag=true);
for(res=num;isdigit(ch=getc());res=res*+num);
(flag)&&(res=-res);
#undef num
return res;
}
const int N=,M=;
int head[N],Next[M],ver[M],edge[M],tot=;
int S,T,dep[N],cur[N],n,m;
queue<int> q;
inline void add(int u,int v,int e){
ver[++tot]=v,Next[tot]=head[u],head[u]=tot,edge[tot]=e;
ver[++tot]=u,Next[tot]=head[v],head[v]=tot,edge[tot]=;
}
bool bfs(){
memset(dep,-,sizeof(dep));
while(!q.empty()) q.pop();
for(int i=S;i<=T;++i) cur[i]=head[i];
q.push(S),dep[S]=;
while(!q.empty()){
int u=q.front();q.pop();
for(int i=head[u];i;i=Next[i]){
int v=ver[i];
if(dep[v]<&&edge[i]){
dep[v]=dep[u]+,q.push(v);
if(v==T) return true;
}
}
}
return false;
}
int dfs(int u,int limit){
if(u==T||!limit) return limit;
int flow=,f;
for(int i=cur[u];i;cur[u]=i=Next[i]){
int v=ver[i];
if(dep[v]==dep[u]+&&(f=dfs(v,min(limit,edge[i])))){
flow+=f,limit-=f;
edge[i]-=f,edge[i^]+=f;
if(!limit) break;
}
}
if(!flow) dep[u]=-;
return flow;
}
int dinic(){
int flow=;
while(bfs()) flow+=dfs(S,inf);
return flow;
}
int main(){
//freopen("testdata.in","r",stdin);
n=read(),m=read(),S=,T=n+;
for(int i=,k;i<=n;++i) k=read(),k&?add(S,i,):add(i,T,);
for(int i=;i<=m;++i){
int u=read(),v=read();add(u,v,),add(v,u,);
}
printf("%d\n",dinic());
return ;
}
05-11 19:56