最小费用最大流模板
来源:互联网 发布:webvr源码 编辑:程序博客网 时间:2024/06/05 11:31
#include <iostream>#include <cstdio>#include <queue>#include <vector>using namespace std;#define ll long longstruct edge{ int u , v , f , c , next; edge(int U = 0 , int V = 0 , int F = 0 , int C = 0 , int Next = 0){ u = U , v = V , f = F , c = C , next = Next; }}e[maxn*maxn];int vis[maxn] , pre[maxn] , head[maxn] ,cnt , source , destinate;ll Max_flow , Min_cost , cost[maxn];void add(int u , int v , int f , int c){ e[cnt] = edge(u , v , f , c , head[u]) , head[u] = cnt++; e[cnt] = edge(v , u , 0 , -1*c , head[v]) , head[v] = cnt++;}void ini(){ for(int i = 0; i < maxn; i++){ for(int j = 0; j < maxn; j++){ e[i*maxn+j] = edge(0 , 0 , 0 , 0 , -1); } vis[i] = 0; pre[i] = -1; cost[i] = inf; head[i] = -1; } cnt = 0; Max_flow = 0; Min_cost = 0;}bool bfs(){ for(int i = 0; i < maxn; i++){ vis[i] = 0; pre[i] = -1; cost[i] = inf; } queue<int> q; q.push(source); cost[source] = 0; while(!q.empty()){ int from = q.front(); q.pop(); vis[from] = 0; for(int next = head[from]; next > -1; next = e[next].next){ int to = e[next].v; if(e[next].f > 0 && cost[from]+e[next].c < cost[to]){ pre[to] = next; cost[to] = cost[from]+e[next].c; if(vis[to] == 0){ vis[to] = 1; q.push(to); } } } } if(pre[destinate] == -1) return false; return true;}ll Max_Flow(){ while(bfs()){ ll flow = inf; for(int from = pre[destinate]; from > -1; from = pre[e[from].u]){ flow = min(flow , (ll)e[from].f); } Min_cost += flow*cost[destinate]; Max_flow += flow; for(int from = pre[destinate]; from > -1; from = pre[e[from].u]){ e[from].f -= flow; e[from^1].f += flow; } } return Max_flow;}int main(){ return 0;}
0 0
- 模板[最小费用最大流]
- 最小费用最大流模板
- 最小费用最大流模板
- 最小费用最大流模板
- 最小费用最大流,模板
- 最小费用最大流模板
- 最小费用最大流 模板
- 最小费用最大流模板
- 最小费用最大流模板
- 最小费用最大流模板
- 最小费用最大流模板
- 最小费用最大流模板
- 最小费用最大流模板
- 最小费用最大流模板
- 最小费用最大流模板
- 最小费用最大流模板
- 最小费用最大流模板
- 最小费用最大流模板
- TTP224 4路电容式触摸开关(数字触摸传感器)模块
- 中文操作系统的VBscript中,使用的是unicode字符集
- iOS开发- UICollectionView详解+实例
- DRIVER_OBJECT & DEVICE_OBJECT
- javascript,ajax 中文乱码
- 最小费用最大流模板
- Gauss Fibonacci
- HTML格式的Form表单文件FOLDER.htm的内容
- 设计模式 策略模式 以角色游戏为背景
- 画出各种自定义的窗体形状
- DriverEntry的context
- 我的第一篇博客就写写我的工作吧
- html中head里的meta标签的用法
- 发布一个破解微软脚本加密算法的vbScript 脚本