求最大流dinic算法模板
//最短增广路,Dinic算法
struct Edge
{
int from,to,cap,flow;
};//弧度 void AddEdge(int from,int to,int cap) //增弧
{
edges.push_back((Edge){from,to,cap,});
edges.push_back((Edge){to,from,,});
m=edges.size();
G[from].push_back(m-);
G[to].push_back(m-);
} struct Dinic{
int n,m,s,t;
vector<Edge> edges;
vector<int> G[maxn];
bool vis[maxn];
int d[maxn];
int cur[maxn]; bool Bfs() //构建分层网络
{
memset(vis,,sizeof(vis));
queue<int> Q;
Q.push(s);
d[s]=;
vis[s]=;
while(!Q.empty())
{
int x=Q.front();
Q.pop();
for(int i=;i<G[x].size();i++)
Edge& e=edges[G[x][i]];
if(!vis[e.to]&&e.cap>e.flow)
{
vis[e.to]=;
d[e.to]=d[x]+;
Q.push(e.to);
}
}
return vis[t];
}
}; int DFS(int x,int a)//沿阻塞流增广
{
if(x==t||a==)
return a;
int flow=,f;
for(int& i=cur[x];i<G[x].size();i++)
{
Edge& e=edges[G[x][i]];
if(d[x]+==d[e.to]&&(f=DFS(e.to,min(a,e.cap-e.flow)))>)
{
e.flow+=f;
edges[G[x][i]^].flow-=f;
flow+=f;
a-=f;
if(a==)
break;
}
}
return flow;
} int Maxflow(int s,int t)
{
this->s=;
this->t=t;
int flow=;
while(BFS())
{
memset(cur,,sizeof(cur));
flow+=DFS(s,inf);
}
return flow;
}
求最大流dinic算法模板的更多相关文章
- POJ 1815 - Friendship - [拆点最大流求最小点割集][暴力枚举求升序割点] - [Dinic算法模板 - 邻接矩阵型]
妖怪题目,做到现在:2017/8/19 - 1:41…… 不过想想还是值得的,至少邻接矩阵型的Dinic算法模板get√ 题目链接:http://poj.org/problem?id=1815 Tim ...
- POJ 3469.Dual Core CPU 最大流dinic算法模板
Dual Core CPU Time Limit: 15000MS Memory Limit: 131072K Total Submissions: 24830 Accepted: 10756 ...
- poj 1273最大流dinic算法模板
#include<stdio.h> #include<string.h> #define N 300 #define inf 0x7fffffff #include<qu ...
- 最大流Dinic算法模板(pascal)
program rrr(input,output); const inf=; type pointer=^nodetype; nodetype=record t,c:longint; next,rev ...
- HDU1532最大流 Edmonds-Karp,Dinic算法 模板
Drainage Ditches Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- POJ 1273 Drainage Ditches(网络流dinic算法模板)
POJ 1273给出M条边,N个点,求源点1到汇点N的最大流量. 本文主要就是附上dinic的模板,供以后参考. #include <iostream> #include <stdi ...
- hdu 2435 dinic算法模板+最小割性质
#include<stdio.h> #include<queue> #include<string.h> using namespace std; #define ...
- 网络流之最大流Dinic算法模版
/* 网络流之最大流Dinic算法模版 */ #include <cstring> #include <cstdio> #include <queue> using ...
- POJ 1273 - Drainage Ditches - [最大流模板题] - [EK算法模板][Dinic算法模板 - 邻接表型]
题目链接:http://poj.org/problem?id=1273 Time Limit: 1000MS Memory Limit: 10000K Description Every time i ...
随机推荐
- 福布斯最佳雇主榜:谷歌母公司Alphabet再登榜首 微软次之
http://www.sohu.com/a/259018538_114774 站长之家(ChinaZ.com) 10月12日 消息:在福布斯发布的最新全球最佳雇主榜单中,谷歌母公司Alphabet以满 ...
- PE结构图示
- valueError: This solver needs samples of at least 2 classes in the data, but the data contains only one class: 0
问题描述:执行下面的代码,报错valueError: This solver needs samples of at least 2 classes in the data, but the data ...
- Spark学习之路 (十九)SparkSQL的自定义函数UDF
在Spark中,也支持Hive中的自定义函数.自定义函数大致可以分为三种: UDF(User-Defined-Function),即最基本的自定义函数,类似to_char,to_date等 UDAF( ...
- 【Hadoop学习之七】Hadoop YARN
环境 虚拟机:VMware 10 Linux版本:CentOS-6.5-x86_64 客户端:Xshell4 FTP:Xftp4 jdk8 hadoop-3.1.1 YARN: ...
- Java -cp 命令查看 zookeeper 日志
- python XML文件解析:用xml.dom.minidom来解析xml文件
python解析XML常见的有三种方法: 一是xml.dom.*模块,是W3C DOM API的实现,若需要处理DOM API则该模块很合适, 二是xml.sax.*模块,它是SAX API的实现,这 ...
- 20165215 2017-2018-2 《Java程序设计》第5周学习总结
20165215 2017-2018-2 <Java程序设计>第5周学习总结 教材学习内容总结 chapter7 Java支持在一个类中声明另外一个类,这样的类称作内部类,而包含内部类的类 ...
- windows环境下 curl 安装和使用
curl下载地址:https://curl.haxx.se/download.html,拉到页面最底下,选择红色选中的那个CAB的进行下载,如下图所示: 下载完成后,解压. 解决windows控制台c ...
- FAQ About WOYO PDR007 Dent Removal Heat Induction System
WOYO PDR 007 is a dent repair tool for auto maintence. WOYO PDR007 Auto Body Paintless Dent Repair K ...