//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. WinCE:在Win7上连接WinCE手持设备

    当我们通过usb将WinCE 手持设备与Win7 PC连接后,我们通常希望通过Windows Mobile Center软件与手持设备实现同步.方法很简单,从下列列表中选择适合自己操作系统的Windo ...

  2. keras与sklearn的结合使用

    keras与sklearn的结合使用 新建 模板 Fly Time: 2017-4-14 引言 代码 引言 众所周知,keras目前没有提供交叉验证的功能,我们要向使用交叉验证,就需要与sklearn ...

  3. 【转】shell中的内建命令, 函数和外部命令

    原文:http://www.cnblogs.com/xkfz007/archive/2011/10/13/2209571.html linux命令有内部命令和外部命令之分.内部命令实际上是shell程 ...

  4. POJ-2201-Cartesian Tree(笛卡尔树)

    Description Let us consider a special type of a binary search tree, called a cartesian tree. Recall ...

  5. 计算几何 二维凸包问题 Andrew算法

    凸包:把给定点包围在内部的.面积最小的凸多边形. Andrew算法是Graham算法的变种,速度更快稳定性也更好. 首先把全部点排序.依照第一keywordx第二keywordy从小到大排序,删除反复 ...

  6. CodeForces 653 A. Bear and Three Balls——(IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2))

    传送门 A. Bear and Three Balls time limit per test 2 seconds memory limit per test 256 megabytes input ...

  7. Spring源代码解析和配置文件载入

    Spring类的继承结构图: Spring运用了大量的模板方法模式和策略模式,所以各位看源代码的时候,务必留意,每个继承的层次都有不同的作用.然后将同样的地方抽取出来,依赖抽象将不同的处理依照不同的策 ...

  8. jQuery - 获取爱好

    <!DOCTYPE html > <html> <head> <title> 获取爱好 </title> <meta http-equ ...

  9. bin/sh^M:损坏的解释器: 没有那个文件或目录

    脚本文件保存时使用了DOS格式,用DOS2UNIX转为UNIX格式,也可以用vim打开,用:set ff=unix转换.不要在 Windows下编辑脚本文件,否则经常会遇到这种问题. 代码:sed - ...

  10. class--类③

    类的构造函数 类的构造函数是类的一种特殊的成员函数,它会在每次创建类的新对象时执行. 构造函数的名称与类的名称是完全相同的,并且不会返回任何类型,也不会返回 void.构造函数可用于为某些成员变量设置 ...