[SHOI2007]BZOJ1934 Vote善意的投票-最小割
来源:互联网 发布:淘宝如何删除好评 编辑:程序博客网 时间:2024/05/21 09:48
题目链接:传送门
题目大意:请自行参考原题
题解:我承认如果不告诉我这是个最小割我是想不到的QWQ
一个同学i的意见是x如果x=1就建边(S,i,1)否则建边(i,T,1)。
如果xy是朋友就建边(x,y,1)&(y,x,1)。
最小割就是答案(割掉某一边表示违背初始意愿)
代码:
//BZOJ1934//SHOI2007 #include<queue>#include<cstdio>#include<climits>#include<cstring>#include<iostream>#include<algorithm>#define MAXN 1000#define MAXM 200000#define INF INT_MAX#define build_edge(u,v,c) add_edge(u,v,c),add_edge(v,u,0)#define P(x,y) (~-(x)*m+(y))#define inrange(x,y) (1<=x&&x<=n&&1<=y&&y<=m)using namespace std;struct edges{int to,pre,resf;}e[MAXM];int etop,h[MAXN],lev[MAXN],cur[MAXN];bool vis[MAXN];queue<int> q;int dx[]={0,-1,0,1,0},dy[]={0,0,1,0,-1};int add_edge(int u,int v,int c){etop++;e[etop].to=v;e[etop].pre=h[u];h[u]=etop;e[etop].resf=c;return 0;}bool bfs(int s,int t){memset(vis,false,sizeof(vis));memset(lev,0,sizeof(lev));while(!q.empty()) q.pop();q.push(s);lev[s]=0;vis[s]=true;while(!q.empty()){int x=q.front();q.pop();for(int i=h[x];i;i=e[i].pre)if(!vis[e[i].to]&&e[i].resf){vis[e[i].to]=true;lev[e[i].to]=lev[x]+1;q.push(e[i].to);}}return vis[t];}int dfs(int s,int t,int a){if(s==t||!a) return a;int flow=0,f;for(int &i=cur[s];i;i=e[i].pre)if(lev[e[i].to]==lev[s]+1&&(f=dfs(e[i].to,t,min(a,e[i].resf)))>0){a-=f;flow+=f;e[i].resf-=f;e[((i-1)^1)+1].resf+=f;if(!a) break;}return flow;}int main(){int n,m,s,t;scanf("%d%d",&n,&m);s=0;t=n+1;for(int i=1;i<=n;i++){int x;scanf("%d",&x);if(x) build_edge(s,i,1);else build_edge(i,t,1);}while(m--){int x,y;scanf("%d%d",&x,&y);add_edge(x,y,1);add_edge(y,x,1);}int flow=0;while(bfs(s,t)){for(int i=s;i<=t;i++)cur[i]=h[i];flow+=dfs(s,t,INF);}printf("%d\n",flow);return 0;}
0 0
- bzoj1934: [Shoi2007]Vote 善意的投票 最小割
- [BZOJ1934][Shoi2007]Vote 善意的投票(最小割)
- [SHOI2007]BZOJ1934 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 善意的投票
- BZOJ1934: [Shoi2007]Vote 善意的投票
- bzoj1934 [Shoi2007]Vote 善意的投票
- BZOJ 1934([Shoi2007]Vote 善意的投票-最小割)
- BZOJ_P1934 [Shoi2007]Vote 善意的投票(最小割)
- bzoj 1934: [Shoi2007]Vote 善意的投票(最小割)
- 【bzoj 1934】[Shoi2007]Vote 善意的投票 最小割
- [BZOJ1934]SHOI2007 Vote|最小割
- ios
- 使用boost线程池(多线程使用opencv处理图片)
- 把自己制作的Python open package发布到PyPI
- HTML 子div在父div中居中显示
- 一个困扰已久的UIScrollView问题
- [SHOI2007]BZOJ1934 Vote善意的投票-最小割
- 1063
- ubuntu 16.04安装ROS环境
- POJ 1130 Alien Security 笔记
- IOS OC内存堆资源使用总结
- 解释Kullback-Leibler散度
- 定时任务Cron表达式详解和案例
- 关于PSNR和cSNR
- 输出<object returned empty description>