最大网络最小流
来源:互联网 发布:上海达观数据公司咋样 编辑:程序博客网 时间:2024/06/06 02:19
const int maxn=805;const int maxm=2000005;int first[maxn],dis[maxn],vis[maxn],pre[maxn];int u[maxm],v[maxm],w[maxm],cost[maxm],flow[maxm],nex[maxm];int n,m,vcnt,ecnt,vcnt1,vcnt2;void add_(int a,int b,int c,int d){ u[ecnt]=a; v[ecnt]=b; w[ecnt]=c; cost[ecnt]=d; flow[ecnt]=0; nex[ecnt]=first[a]; first[a]=ecnt++; u[ecnt]=b; v[ecnt]=a; w[ecnt]=0; cost[ecnt]=-d; flow[ecnt]=0; nex[ecnt]=first[b]; first[b]=ecnt++; //cout<<"----"<<a<<" "<<b<<c<<d<<endl;}bool Spfa(int s,int t){ queue<int>q; memset(dis,0x3f,sizeof dis); memset(vis,0,sizeof vis); memset(pre,-1,sizeof pre); dis[s]=0; vis[s]=1; q.push(s); while(!q.empty()) { int x=q.front();q.pop(); vis[x]=0; for(int e=first[x];~e;e=nex[e]) if(w[e]>flow[e]&&dis[v[e]]>dis[x]+cost[e]) { dis[v[e]]=dis[x]+cost[e]; pre[v[e]]=e; if(!vis[v[e]]) { vis[v[e]]=1; q.push(v[e]); } } } if(pre[t]==-1)return false; return true;}int mcmf(int s,int t,int &co){ int flo=0; co=0; while(Spfa(s,t)) { int mmin=inf; for(int i=pre[t];~i;i=pre[v[i^1]]) { mmin=min(mmin,w[i]-flow[i]); } for(int i=pre[t];~i;i=pre[v[i^1]]) { flow[i]+=mmin; flow[i^1]-=mmin; co+=cost[i]*mmin; } flo+=mmin; } return flo;}
0 0
- 最大网络最小流
- 最小网络最大流
- 网络最大流和最小费用流
- 网络流最大流最小割算法
- 网络流最大流最小割算法
- 网络最大流和最小费用流
- 【最大流+最小费用流】网络扩容
- [网络流] 最大流 最小费 回顾
- 网络流 最小割最大流定理
- 网络流 最小费用最大流问题
- 网络流 最小费用最大流
- 网络流-最小费用最大流
- 网络流问题-最小费用最大流
- 网络流-最小费用最大流
- 网络流--最小费用最大流
- 网络的最大流最小割定理
- 网络流-最大流&最小费用最大流
- 【ZJOI2010】【最大流】【最小费用最大流】网络扩容
- 如何决定 Web 应用的线程池大小
- 使用jstl c:when报500的教训
- LeetCode Combination Sum II
- Message: Access to the registry key 'Global' is denied.
- 解决logstash1.4.2在windows上文件源读会对文件进行锁定的问题
- 最大网络最小流
- 杭电2564----词组缩写
- Xcode上传ipa时itunes提示you are not authorized to use this service
- leetcode之Repeated DNA Sequences
- Oracle EBS GL经常性日记帐(2)-复杂公式的设置和理解
- dll获得自身路径位置
- MFC 学习之 模态对话框图片控件上作图
- android如何实现开机自动启动Service或app
- Python学习笔记(二)变量类型