bzoj1934 [Shoi2007]Vote 善意的投票
来源:互联网 发布:淘宝面膜销量排行榜 编辑:程序博客网 时间:2024/06/07 09:31
题目
同样的,我们也是分成赞同与不赞同两个集合,也是最小割。
把源点连向赞同,容量为1,不赞同连向汇点,容量为1,再考虑每个人之间的影响,把互相为好朋友之间连双向边,容量为1。
这还是比较简单的网络流。
#include<bits/stdc++.h>#define inf ~0u>>1#define N 305#define M 200000using namespace std;int n,m,S,T,x,y;int first[N+1],nex[M+1],to[M+1],fl[M+1],siz;int dis[N+1];inline char nc(){ static char buf[100000],*p1=buf,*p2=buf; return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;}inline int read(){ int x=0,b=1; char c=nc(); for(;!(c<='9'&&c>='0');c=nc())if(c=='-')b=-1; for(;c<='9'&&c>='0';c=nc())x=x*10+c-'0'; return x*b;}inline void add(int x,int y,int z){ nex[siz]=first[x]; first[x]=siz; to[siz]=y; fl[siz]=z; siz++;}inline void insert(int x,int y,int z){ add(x,y,z),add(y,x,0);}inline bool BFS(int s,int t){ queue <int> Q; for(int i=S;i<=T;i++)dis[i]=inf; dis[s]=0,Q.push(s); while(!Q.empty()) { int x=Q.front();Q.pop(); for(int i=first[x];i!=-1;i=nex[i]) { int u=to[i]; if(fl[i]&&dis[x]+1<dis[u]) { dis[u]=dis[x]+1; if(u==t)return true; Q.push(u); } } } if(dis[t]==inf)return false;return true;}inline int DFS(int s,int f,int t){ if(s==t)return f; int rest=f; for(int i=first[s];i!=-1;i=nex[i]) { int u=to[i]; if(fl[i]&&rest&&dis[u]==dis[s]+1) { int tmp=DFS(u,min(rest,fl[i]),t); if(tmp==0)dis[u]=0; fl[i]-=tmp; fl[i^1]+=tmp; rest-=tmp; } } return f-rest;}inline int Dinic(int s,int t){ int ans=0; while(BFS(s,t))ans+=DFS(s,inf,t); return ans;}int main(){ //freopen("in.txt","r",stdin); memset(first,-1,sizeof(first)); n=read(),m=read(); S=0,T=n+1; for(int i=1;i<=n;i++) { x=read(); if(x)insert(S,i,1); else insert(i,T,1); } for(int i=1;i<=m;i++) { x=read(),y=read(); insert(x,y,1); insert(y,x,1); } cout<<Dinic(S,T); return 0;}
注意,双向边,可以在连反向边时直接把容量设了,就不用为0的了。
阅读全文
0 0
- 【bzoj1934】 [Shoi2007]Vote 善意的投票
- bzoj1934【shoi2007】Vote善意的投票
- [bzoj1934]: [Shoi2007]Vote 善意的投票
- bzoj1934: [Shoi2007]Vote 善意的投票
- bzoj1934 [Shoi2007]Vote 善意的投票
- BZOJ1934: [Shoi2007]Vote 善意的投票
- bzoj1934 [Shoi2007]Vote 善意的投票
- bzoj1934: [Shoi2007]Vote 善意的投票 最小割
- [BZOJ1934][Shoi2007]Vote 善意的投票(最小割)
- [SHOI2007]BZOJ1934 Vote善意的投票-最小割
- [bzoj1934][SHOI2007] Vote 善意的投票 最小割
- BZOJ1934 [Shoi2007]Vote 善意的投票 【最小割】
- bzoj1934 [Shoi2007]Vote 善意的投票(最小割)
- 【SHOI2007】bzoj1934 善意的投票
- BZOJ 1934: [Shoi2007]Vote 善意的投票
- bzoj 1934: [Shoi2007]Vote 善意的投票
- 【BZOJ 1934】 [Shoi2007]Vote 善意的投票
- BZOJ-1934-Vote善意的投票-SHOI2007
- jsday06(window小广告)
- bzoj1237 [SCOI2008]配对
- 人脸识别:Deep Face Recognition论文阅读
- bzoj1412 [ZJOI2009]狼和羊的故事
- bzoj1433 [ZJOI2009]假期的宿舍
- bzoj1934 [Shoi2007]Vote 善意的投票
- bzoj2127 happiness
- 精度保证下的新型深度网络压缩框架
- bzoj3192 [JLOI2013]删除物品
- bzoj4403 序列统计
- bzoj4562 [Haoi2016]食物链
- bzoj4993 [Usaco2017 Feb]Why Did the Cow Cross the Road II
- bzoj4994 [Usaco2017 Feb]Why Did the Cow Cross the Road III
- Oracle 学习笔记 图解深入剖析一个事务的操作流程