Network-Flow
//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的更多相关文章
- 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 ...
- 数据结构与算法分析 - 网络流入门(Network Flow)
转载:网络流基础篇--Edmond-Karp算法 BY纳米黑客 网络流的相关定义: 源点:有n个点,有m条有向边,有一个点很特殊,只出不进,叫做源点. 汇点:另一个点也很特殊, ...
- 1000: A+B Problem(NetWork Flow)
1000: A+B Problem Time Limit: 1 Sec Memory Limit: 5 MBSubmit: 11814 Solved: 7318[Submit][Status][D ...
- 数据结构之网络流入门(Network Flow)简单小节
网络流的相关定义: 源点:有n个点,有m条有向边,有一个点很特殊,只出不进,叫做源点. 汇点:另一个点也很特殊,只进不出,叫做汇点. 容量和流量:每条有向边上有两个量,容量和流量,从i到j的容量通常用 ...
- 网络流$1$·简单的$EK$与$Dinic~of~Net-work ~ Flow$学习笔记
\(2333\)这是好久之前学的了,不过一直在咕咕咕咕. 一般来讲,正常的网络流笔记一开始都是要给网络流图下定义的.那么我们不妨也来先进行一波这种操作. 那么网络流图,类似于有向图,边上带权,但是这个 ...
- 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 ...
- HDU 3549 Flow Problem(最大流)
HDU 3549 Flow Problem(最大流) Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/ ...
- hdu------(3549)Flow Problem(最大流(水体))
Flow Problem Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Tota ...
- hdu 3549 Flow Problem
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=3549 Flow Problem Description Network flow is a well- ...
- hdu 3549 Flow Problem 网络流
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3549 Network flow is a well-known difficult problem f ...
随机推荐
- 中国银联mPOS通用技术安全分析和规范解读
mPOS是近年出现并得到迅速发展的一种新型受理产品,不少机构和生产企业进行了各种形式的试点. 因为mPOS引入了手机.平板电脑等通用智能移动设备.并通过互联网进行信息传输.因此其安全特点与传统银行卡受 ...
- 【cocos2d-x 3.7 飞机大战】 决战南海I (十) 游戏主场景
主场景要包括其它类的头文件 #include "cocos2d.h" #include "MyPlane.h" #include "Bullet.h& ...
- Axure RP一个专业的高速原型设计工具
Axure RP是一个专业的高速原型设计工具.Axure(发音:Ack-sure),代表美国Axure公司.RP则是Rapid Prototyping(高速原型)的缩写. Axure简要介绍 Axur ...
- 《鸟哥的Linux私房菜-基础学习篇(第三版)》(五)
第4章 安装CentOS 5.x与多重引导小技巧 1. 本练习机的规划(尤其是分区參数) 分了四个分区: 1)/boot:primary 2)/:primary 3)/ho ...
- Facebook图搜索unicorn
unicorn(独角兽),里面类似于倒排链的reference list,相应的term如friend:2,表示entity 2的朋友列表,整个结构是shard的,上面是top aggregator, ...
- React Native布局实践:开发京东client首页(三)——轮播图的实现
上篇文章中,我们一起构建了京东client的TabBar.在本文中.将继续向大家介绍京东client首页轮播图及其下发功能button的开发方法,如今就让我们開始吧! 1.相关控件调研 眼下在Gith ...
- 用Thymeleaf在前台下拉列表取值
转自:https://blog.csdn.net/u013600907/article/details/76165748
- Js:弹窗剧中
js变量设置 var iWidth = $(window).width() * 0.9; var iHeight = $(window).height() * 0.9; - iHeight) / ; ...
- IP地址库
吐槽 前两天一个线上的IP地址库除了点幺蛾子,一查代码,发现用的库早就不更新了,遂决定换库,有几个方案: 纯真数据库 IPIP数据库 GeoIP 纯真数据库是大码农的福音,免费,但是精度一般:IPIP ...
- POJ 1753 DFS
思路: 有过两个裸搜的思路,第一个一个无限TLE,第二个还不慢... 错误思路:迭代加深搜索,枚举翻第几个棋,挂的原因:16的16次方,不挂就怪了. 错误代码见下: #include <cstd ...