【BZOJ 1934】 [Shoi2007]Vote 善意的投票
来源:互联网 发布:淘宝如何设置冰点促销 编辑:程序博客网 时间:2024/05/18 00:34
快算是BZOJ最水题了吧
明显的最小割
这样我还看题解 明明都(快)想出来了....
下次 一定争取自己A上一道!!!!!!!!!!!!!
Orz ws_fqk 刷的这么快!!
#include <cstdio>#include <iostream>#include <algorithm>#include <cstring>#include <cstdlib>using namespace std;#define MAXN 550#define INF 100000000int n,m,s,t;int tot=2,g[MAXN],num[1000000],nnext[1000000],flow[1000000];int d[1000000],team[1000000],head,tail;void Add(int x,int y,int z){nnext[tot]=g[x];g[x]=tot;num[tot]=y,flow[tot]=z;tot++;}bool bfs(){ head=tail=0;memset(d,0,sizeof(d)); d[s]=1;team[++tail]=s; while(head<tail) { int x=team[++head]; for(int i=g[x];i;i=nnext[i]) { int tmp=num[i]; if(d[tmp]==0&&flow[i]!=0) d[tmp]=d[x]+1,team[++tail]=tmp; } } if(d[t]==0) return false; return true;}int dfs(int x,int mmin){ if(x==t) return mmin; int f=0,tmp; for(int i=g[x];i;i=nnext[i]) if(d[num[i]]==d[x]+1&&flow[i]!=0&&(tmp=dfs(num[i],min(mmin,flow[i])))) { flow[i]-=tmp; flow[i^1]+=tmp; f+=tmp,mmin-=tmp; if(mmin==0) return f; } return f;}int main(){ scanf("%d %d",&n,&m);s=n+1,t=n+2; for(int i=1,tmp;i<=n;i++) { scanf("%d",&tmp); if(tmp==1) Add(s,i,1),Add(i,s,0); else Add(i,t,1),Add(t,i,0); } for(int x,y,i=1;i<=m;i++) { scanf("%d %d",&x,&y); Add(x,y,1); Add(y,x,1); } int ans=0; while(bfs()) ans+=dfs(s,INF); printf("%d\n",ans); return 0;}
0 0
- BZOJ 1934: [Shoi2007]Vote 善意的投票
- bzoj 1934: [Shoi2007]Vote 善意的投票
- 【BZOJ 1934】 [Shoi2007]Vote 善意的投票
- BZOJ-1934-Vote善意的投票-SHOI2007
- 【BZOJ 1934】 [Shoi2007]Vote 善意的投票
- BZOJ 1934 [Shoi2007]Vote 善意的投票
- BZOJ 1934: [Shoi2007]Vote 善意的投票
- BZOJ 1934([Shoi2007]Vote 善意的投票-最小割)
- bzoj 1934: [Shoi2007]Vote 善意的投票(最小割)
- 【bzoj 1934】[Shoi2007]Vote 善意的投票 最小割
- 1934: [Shoi2007]Vote 善意的投票
- 1934: [Shoi2007]Vote 善意的投票
- 1934: [Shoi2007]Vote 善意的投票 (网络流)
- 2768: [JLOI2010]冠军调查/1934: [Shoi2007]Vote 善意的投票
- 【bzoj1934】 [Shoi2007]Vote 善意的投票
- bzoj1934【shoi2007】Vote善意的投票
- [bzoj1934]: [Shoi2007]Vote 善意的投票
- bzoj1934: [Shoi2007]Vote 善意的投票
- 【BZOJ 3504 】[Cqoi2014]危桥
- Java 利用过滤器Filter 实现登录过滤
- 【Poj 3469】 Dual Core CPU
- 【COGS 1873】 [国家集训队2011]happiness(吴确)
- 【BZOJ 1433】 [ZJOI2009]假期的宿舍
- 【BZOJ 1934】 [Shoi2007]Vote 善意的投票
- 【BZOJ 2705】 [SDOI2012]Longge的问题
- 【BZOJ 3990】 [SDOI2015]排序
- 【洛谷 1345】 奶牛的电信
- basler 相机使用出现的问题
- 【洛谷 1991】 无线通讯网
- 【CodeVS 1540】银河英雄传说 2002年NOI全国竞赛
- 【BZOJ 1798】[Ahoi2009]Seq 维护序列seq
- 【洛谷 2161】 [Shoi2009]Booking 会场预约