//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. SegmentFault 巨献 1024 程序猿游戏「红岸的呼唤」第一天任务攻略

    今天一不小心在微博上看到了SegmentFault的一条微博: 眼看今天就要过去了,那在这里说一下我的解题过程(事实上大家都知道了吧-=). 高速传送门:http://segmentfault.com ...

  2. LINQ体验(2)——C# 3.0新语言特性和改进(上篇)

    整体来说.Visual Studio 2008和.NET 3.5是建立在.NET2.0核心的基础之上,.NET2.0核心本身将不再变化(假设不了解.NET2.0的朋友,请參看MSDN或者一些经典的书籍 ...

  3. 数据结构(C实现)------- 顺序栈

    栈是限定仅在表的一端进行插入或删除的纯属表,通常称同意插入.删除的一端为栈顶(Top),对应在的.则称还有一端为栈底(Bottom). 不含元素的栈则称为空栈. 所设栈S={a1,a2,a3,..., ...

  4. 【Linux】Ubuntu 开机默认亮度改动方法

    换了ubuntu 之后.发现开机屏幕都是"最大亮度",每次都要到设置中手动调节,非常麻烦.于是想到去改动这个设置.Google一通,别人可行的办法到我这就没用了.郁闷.最后是在st ...

  5. hihoCoder - 1079 - 离散化 (线段树 + 离散化)

    #1079 : 离散化 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描写叙述 小Hi和小Ho在回国之后,又一次过起了朝7晚5的学生生活.当然了.他们还是在一直学习着各种算法 ...

  6. Realm Update failed - Android

    Realm Update failed - Android Ask Question up vote 0 down vote favorite I'm using realm for my andro ...

  7. 使用匿名类型做为ComboBox的DataSource

    使用匿名类型做为ComboBox的DataSource   ArrayList list = new ArrayList();            list.Add(new { id = " ...

  8. poj--1101--The Game(bfs)

    The Game Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9746   Accepted: 2967 Descript ...

  9. [Apple开发者帐户帮助]二、管理你的团队(4)离开一个团队

    您可以随时离开组织的开发团队.但是,帐户持有人有法律责任,只能在指定另一个团队成员作为帐户持有人后离开团队. 如果您是Apple Developer Program中的团队成员,则可以将团队留在App ...

  10. JavaScript 获取星期几函数

    function getDayofWeek() {            var day = "";            var time = new Date();       ...