//Created by pritry
int graph[MAX][MAX]; //原图
int source; //起点,这里为0
int sink; //终点,这里为n-1
int e[MAX]; //余流
int h[MAX]; //高度
int n; //顶点数
struct Label
{
int index;
friend bool operator < (const Label& a, const Label& b)
{
return h[a.index] > h[b.index];
}
};
void Push(int u, int v)
{
int df = min(e[u], graph[u][v]);
graph[u][v] -= df;
graph[v][u] += df;
e[u] -= df;
e[v] += df;
}
void Relabel(int u)
{
int min_h = INF;
for(int i = ; i < n; ++i)
{
if(graph[u][i] && h[i] < min_h)
{
min_h = h[i];
}
}
h[u] = min_h + ;
}
int HLPP()
{
int i;
Label l;
priority_queue<Label> Q;
memset(e, , sizeof(e));
memset(h, , sizeof(h));
h[source] = n;
for(i = ; i < n; ++i)
{
if(graph[source][i])
{
int df = graph[source][i];
e[source] -= df;
e[i] += df;
graph[source][i] -= df;
graph[i][source] += df;
l.index = i;
if(i != source && i != sink) Q.push(l);
}
}
while(!Q.empty())
{
l = Q.top();
Q.pop();
int u = l.index;
while(e[u])
{
for(i = ; i < n; ++i)
if(graph[u][i] && h[u] > h[i])
break; if(i == n) Relabel(u); for(i = ; i < n; ++i)
{
if(h[u] == h[i] + && graph[u][i])
{
Push(u, i);
l.index = i;
if(e[i] > && i != source && i != sink) Q.push(l);
}
}
}
}
return e[sink];
}

Network-Flow的更多相关文章

  1. Multi-target tracking by Lagrangian relaxation to min-cost network flow

    Multi-target tracking by Lagrangian relaxation to min-cost network flow high-order constraints min-c ...

  2. 数据结构与算法分析 - 网络流入门(Network Flow)

    转载:网络流基础篇--Edmond-Karp算法             BY纳米黑客 网络流的相关定义: 源点:有n个点,有m条有向边,有一个点很特殊,只出不进,叫做源点. 汇点:另一个点也很特殊, ...

  3. 1000: A+B Problem(NetWork Flow)

    1000: A+B Problem Time Limit: 1 Sec  Memory Limit: 5 MBSubmit: 11814  Solved: 7318[Submit][Status][D ...

  4. 数据结构之网络流入门(Network Flow)简单小节

    网络流的相关定义: 源点:有n个点,有m条有向边,有一个点很特殊,只出不进,叫做源点. 汇点:另一个点也很特殊,只进不出,叫做汇点. 容量和流量:每条有向边上有两个量,容量和流量,从i到j的容量通常用 ...

  5. 网络流$1$·简单的$EK$与$Dinic~of~Net-work ~ Flow$学习笔记

    \(2333\)这是好久之前学的了,不过一直在咕咕咕咕. 一般来讲,正常的网络流笔记一开始都是要给网络流图下定义的.那么我们不妨也来先进行一波这种操作. 那么网络流图,类似于有向图,边上带权,但是这个 ...

  6. BZOJ1305/Luogu3153 [CQOI2009]dance跳舞 (network flow)

    #define T 1001 #define S 0 struct Edge{ int nxt,pre,w; }e[500007]; int cntEdge,head[N]; inline void ...

  7. HDU 3549 Flow Problem(最大流)

    HDU 3549 Flow Problem(最大流) Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/ ...

  8. hdu------(3549)Flow Problem(最大流(水体))

    Flow Problem Time Limit: 5000/5000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Tota ...

  9. hdu 3549 Flow Problem

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=3549 Flow Problem Description Network flow is a well- ...

  10. hdu 3549 Flow Problem 网络流

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3549 Network flow is a well-known difficult problem f ...

随机推荐

  1. CodeForces - 735D Taxes (哥德巴赫猜想)

    Taxes time limit per test 2 seconds memory limit per test 256 megabytes input standard input output ...

  2. bzoj 3029 守卫者的挑战 —— 概率DP

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3029 设 f[i][j][k] 表示第 i 次挑战,已经成功 j 次,剩余容量为 k 的概率 ...

  3. 逻辑回归 C++

    #include <iostream>#include <string>#include <fstream>#include <sstream>#inc ...

  4. 99.ext afteredit事件详解

    转自:http://www.jcodecraeer.com/a/jquery_js_ajaxjishu/2012/0524/203.html 1 摘要 grid.on(afteredit,afterE ...

  5. 浅讲ajax

    1.ajax入门案例 1.1 搭建Web环境 ajax对于各位来说,应该都不陌生,正因为ajax的产生,导致前台页面和服务器之间的数据传输变得非常容易,同时还可以实现页面的局部刷新.通过在后台与服务器 ...

  6. [Apple开发者帐户帮助]二、管理你的团队(6)找到您的团队ID

    该组ID是已分配给您的团队苹果产生了独特的10个字符的字符串.您需要为某些活动提供您的团队ID, 例如将您的应用程序转移到App Store Connect中的其他开发人员. 在您的开发者帐户中,单击 ...

  7. Django day17 博客项目(一)

    一: 博客项目需求分析 首页(显示文章) 文章详情 点赞, 点踩 文章评论 字评论 评论的展示 登录功能(图片验证码) 注册功能(基于form验证,ajax) 个人站点(不同人不同样式,文章过滤) 后 ...

  8. webapi时间字段返回格式设置及返回model首字母小写

    GlobalConfiguration.Configuration.Formatters.Remove(new XmlMediaTypeFormatter()); // 解决json序列化时的循环引用 ...

  9. android开源新闻小程序、3D翻转公告效果、小说检索、Kotlin开发TODO清单等源码

    Android精选源码 开源新闻小程序源码分享 android动态壁纸.锁屏动画.来电秀等源码 android笔记App效果源码 Android实现3D版翻页公告效果 android小说搜索阅读源码 ...

  10. ie8及其以下版本兼容性问题之input file隐藏上传文件

    文件上传时,默认的file标签很难看,而且每个浏览器下都有很大差距.因此我们基本都把真正的file标签给隐藏,然后创建一个标签来替代它.但是由于IE出于安全方面的考虑上传文件时必须点击file的浏览按 ...