Net FLow Template
EK Template :
bool bfs(int src, int des){
memset(pre, -, sizeof(pre));
while(!que.empty()) que.pop();
pre[src] = ;
int index;
que.push(src);
while(!que.empty()){
index = que.front();
que.pop();
for(int i = src; i <= des; ++i){
if(pre[i] == - && map[index][i] > ){
pre[i] = index;
if(i == des) return true;
que.push(i);
}
}
}
return false;
}
int MaxFlow(int src, int des){
int maxflow = ;
while(bfs(src, des)){
int minflow = INF;
int i;
for(i = des; i != src; i = pre[i])
minflow = min(minflow, map[pre[i]][i]);
for(i = des; i != src; i = pre[i]){
map[pre[i]][i] -= minflow;
map[i][pre[i]] += minflow;
}
maxflow += minflow;
}
return maxflow;
}
SAP + GAP Template :
int sap(int u,int flow){
if(u == src) return flow;
int ans = , i, t;
for(i = src; i <= des; ++i)
if(map[u][i] && dis[u] == dis[i] + ){
t = sap(i, min(flow - ans, map[u][i]));
map[u][i] -= t, map[i][u] += t,ans += t;
if(ans == flow) return ans;
}
if(dis[src] >= n + ) return ans;
if(!--gap[dis[u]]) dis[src] = n + ;
++gap[++dis[u]];
return ans;
}
src = 1, des = n;
for(gap[0] = n + 2; dis[src] < n + 2; )
ans += sap(src,INF);
Net FLow Template的更多相关文章
- 在vue中配置flow类型检查
flow中文文档:https://zhenyong.github.io/flowtype/docs/objects.html#_ 1.安装flow npm install --save-dev flo ...
- LTE Module User Documentation(翻译8)——核心网(EPC)
LTE用户文档 (如有不当的地方,欢迎指正!) 14 Evolved Packet Core (EPC) 我们现在讲解如何编写一个仿真程序——除了 LTE 无线接入网外,还允许仿真 EPC. EP ...
- PDP 有多种定义,具体哪一种还需研究!!!!
PDP (用户面进行隧道转发的信息的保存协议) 编辑 本词条缺少名片图,补充相关内容使词条更完整,还能快速升级,赶紧来编辑吧! 即PDP上下文,保存用户面进行隧道转发的所有信息,包括RNC/GGSN的 ...
- GTP V0 和 GTP V1
GTP概述 GTP(GPRS Tunnelling Protocol)协议应用在SGSN 和GGSN 之间,为各个移动台(MS) 建立GTP 通道,GTP 通道是 GPRS服务节点(GSN) 之间的安 ...
- BPEL_Oracle BPEL新一代工作流介绍(概念)
2014-11-02 Created By BaoXinjian
- POJ 3422 Kaka's Matrix Travels (K取方格数:最大费用流)
题意 给出一个n*n大小的矩阵,要求从左上角走到右下角,每次只能向下走或者向右走并取数,某位置取过数之后就只为数值0,现在求解从左上角到右下角走K次的最大值. 思路 经典的费用流模型:K取方格数. 构 ...
- PDP context
PDP context[edit] The packet data protocol (PDP; e.g., IP, X.25, FrameRelay) context is a data struc ...
- eMTC/NB/LTE拨号
挂起-恢复流程挂起恢复流程是eMTC/NB-IoT等蜂窝物联网技术才引进的,LTE并不具备这样的流程.这种机制的引入主要针对物联网海量连接,不活跃小数据包的特点,适时的挂起流程可以减少网络的资源开销, ...
- 国庆大礼包:2014年最全的ANDROID GUI模板和线框图免费下载
距离上次分享GUI模板有很长时间了,这段时间里设计趋势不断变化,谷歌推出了最新的Android L以及全新的界面设计,UI设计师又有得忙了,今天收集了一组实用的GUI模板和线框图,包含最新的Andro ...
随机推荐
- [LeetCode]题解(python):080-Remove Duplicates from Sorted Array II
题目来源: https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii/ 题意分析: 跟定一个排好序的数组.修改这个数组使 ...
- viewpager的layout_width="wrap_content"无效问题
在viewpager当中直接使用layout_width="wrap_content"是无效的,扩展了一下.解决这个问题. package com.soulagou.ui; imp ...
- Spring 拦截器实现事物
Spring+Hibernate的实质:就是把Hibernate用到的数据源Datasource,Hibernate的SessionFactory实例,事务管理器HibernateTransactio ...
- c基础总结
机器大小端判断: #include <stdio.h> typedef union{ char x; int i; }un; int main() { un tt; tt.i = ; ) ...
- gridview的高级使用
后台数据 using System; using System.Collections.Generic; using System.Linq; using System.Web; using Sy ...
- 对象作为返回值类型&&链式编程
package com.imooc; class Student{ public void study(){ System.out.println("学生学习"); } } cla ...
- C++对C语言的非面向对象特性扩充(2)
上一篇随笔写了关于C++在注释,输入输出,局部变量说明的扩充,以及const修饰符与C中的#define的比较,也得到了几位学习C++朋友们的帮助讲解,十分感谢,我也希望欢迎有更多学习C++的朋友一起 ...
- 对面向对象的理解—— SAP电面(1)
对于C++面向对象的理解 面向对象是在结构化设计方法出现很多问题的情况下应运而生的.结构化设计方法求解问题的基本策略是从功能的角度审视问题域.它将应用程序看成实现某些特定任务的功能模块,其中子过程是实 ...
- BZOJ 1856: [Scoi2010]字符串( 组合数 )
求(0,0)->(n,m)且在直线y=x下方(可以在y=x上)的方案数...同 http://www.cnblogs.com/JSZX11556/p/4908648.html --------- ...
- python成长之路10
断点续传 python2.7 多继承 py35多继承 socketserver源码 支持并发处理socket i/o多路复用 上节回顾 socket ...