[BZOJ1497][NOI2006]最大获利(最小割)
来源:互联网 发布:温度数据采集程序 编辑:程序博客网 时间:2024/05/16 08:23
题目描述
传送门
题解
对于每一个中转站,s->i,pi,割掉表示花费pi建立中转站
对于每一个顾客,i->t,ci,割掉表示放弃ci的收益
如果一个顾客x需要某一个中转站y,那么y->x,inf,因为py和cx不能同时满足,必须选一条割掉
所有顾客的收益之和减去最小割即为答案
代码
#include<algorithm>#include<iostream>#include<cstring>#include<cstdio>#include<cmath>#include<queue>using namespace std;#define N 100005#define inf 1000000000int n,m,p,a,b,c,s,t,sum,maxflow;int tot,point[N],nxt[N*4],v[N*4],remain[N*4];int deep[N],cur[N],last[N],num[N];queue <int> q;void addedge(int x,int y,int cap){ ++tot; nxt[tot]=point[x]; point[x]=tot; v[tot]=y; remain[tot]=cap; ++tot; nxt[tot]=point[y]; point[y]=tot; v[tot]=x; remain[tot]=0;}void bfs(int t){ for (int i=s;i<=t;++i) deep[i]=t; deep[t]=0; for (int i=s;i<=t;++i) cur[i]=point[i]; while (!q.empty()) q.pop(); q.push(t); while (!q.empty()) { int now=q.front();q.pop(); for (int i=point[now];i!=-1;i=nxt[i]) if (deep[v[i]]==t&&remain[i^1]) { deep[v[i]]=deep[now]+1; q.push(v[i]); } }}int addflow(int s,int t){ int now=t,ans=inf; while (now!=s) { ans=min(ans,remain[last[now]]); now=v[last[now]^1]; } now=t; while (now!=s) { remain[last[now]]-=ans; remain[last[now]^1]+=ans; now=v[last[now]^1]; } return ans;}void isap(int s,int t){ bfs(t); for (int i=s;i<=t;++i) ++num[deep[i]]; int now=s; while (deep[s]<t) { if (now==t) { maxflow+=addflow(s,t); now=s; } bool has_find=false; for (int i=cur[now];i!=-1;i=nxt[i]) if (deep[v[i]]+1==deep[now]&&remain[i]) { has_find=true; cur[now]=i; last[v[i]]=i; now=v[i]; break; } if (!has_find) { int minn=t-1; for (int i=point[now];i!=-1;i=nxt[i]) if (remain[i]) minn=min(minn,deep[v[i]]); if (!(--num[deep[now]])) break; ++num[deep[now]=minn+1]; cur[now]=point[now]; if (now!=s) now=v[last[now]^1]; } }}int main(){ tot=-1;memset(point,-1,sizeof(point)); scanf("%d%d",&n,&m); s=1,t=n+m+2; for (int i=1;i<=n;++i) { scanf("%d",&p); addedge(s,1+i,p); } for (int i=1;i<=m;++i) { scanf("%d%d%d",&a,&b,&c); addedge(1+n+i,t,c); addedge(1+a,1+n+i,inf); addedge(1+b,1+n+i,inf); sum+=c; } isap(s,t); printf("%d\n",sum-maxflow);}
0 0
- [BZOJ1497][NOI2006]最大获利(最小割)
- bzoj1497 NOI2006 最大获利 最小割
- bzoj1497 [NOI2006]最大获利(最大权闭合图,最小割)
- BZOJ1497 NOI2006最大获利
- [BZOJ1497][NOI2006]最大获利
- bzoj1497[NOI2006]最大获利
- bzoj1497【NOI2006】最大获利
- 【bzoj1497】NOI2006最大获利
- 【NOI2006】BZOJ1497最大获利
- BZOJ1497: [NOI2006]最大获利
- bzoj1497 [NOI2006]最大获利
- [NOI2006]最大获利 BZOJ1497
- bzoj1497: [NOI2006]最大获利
- BZOJ1497 [NOI2006] 最大获利
- BZOJ1497: [NOI2006]最大获利
- bzoj1497 [NOI2006]最大获利
- bzoj1497: [NOI2006]最大获利(最大权闭合子图,最小割)
- 最小割模型——最大权闭合子图 【NOI2006】bzoj1497 最大获利
- HDU 2034 人见人爱A-B
- [bzoj1951][SDOI2010]古代猪文
- MIT 线性代数(4—6)读书笔记
- 我们是如何认识这个世界的呢
- 由拜年红包引起的程序架构思考
- [BZOJ1497][NOI2006]最大获利(最小割)
- opencv车牌识别入门资料汇总
- python 方法记录
- 一些用语概念
- 一道关于给DIV按比例分配宽度的面试题
- mybatis generator xml提示错误 - URI is not registered 解决
- [Node.js]Buffer
- 递推计算方法之快速幂计算
- Nullable<T>,?,??使用