网络流dinic板子
bool bfs(){
memset(deep,0,sizeof(deep));
queue<int>que;
que.push(s);
deep[s]=1;
while(!que.empty()){
int u=que.front();
que.pop();
for(int i=head[u];i!=-1;i=e[i].nextt){
int v=e[i].v;
if(e[i].w>0&&deep[v]==0){
deep[v]=deep[u]+1;
if(v==t)
return true;
que.push(v);
}
}
}
return deep[t]==0?false:true;
}
int dfs(int u,int fl){
if(u==t)
return fl;
int ans=0,x=0;
for(int i=cur[u];i!=-1;i=e[i].nextt){
int v=e[i].v;
if(e[i].w>0&&deep[v]==deep[u]+1){
x=dfs(v,min(e[i].w,fl-ans));
e[i].w-=x;
e[i^1].w+=x;
if(e[i].w)
cur[u]=i;
ans+=x;
if(ans==fl)
return ans;
}
}
if(ans==0)
deep[u]=0;
return ans;
}
int dinic(int n){
int ans=0;
while(bfs()){
for(int i=0;i<=n;i++)
cur[i]=head[i];
ans+=dfs(s,inf);
}
return ans;
}
网络流dinic板子的更多相关文章
- POJ 1273 Drainage Ditches (网络流Dinic模板)
Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover ...
- 最大网络流dinic
初始化flow(最大流量)为INF(极大值),建边(正向弧和反向弧) bfs寻找增广路看看有没有路,顺便进行深度标号.如果没有路直接结束输出flow. 如果有,我们按照深度dfs.dfs时注意在给正向 ...
- ACM/ICPC 之 有流量上下界的网络流-Dinic(可做模板)(POJ2396)
//有流量上下界的网络流 //Time:47Ms Memory:1788K #include<iostream> #include<cstring> #include<c ...
- 网络流Dinic(本篇介绍最大流)
前言:看到网上Dinic和ISAP的比较,多数人认为ISAP更快,不容易爆栈.当然,也有少数人认为,在多数情况下,Dinic比较稳定.我认为Dinic的思路比ISAP更简明,所以选择了Dinc算法 介 ...
- Drainage Ditches(POJ1273+网络流+Dinic+EK)
题目链接:poj.org/problem?id=1273 题目: 题意:求最大流. 思路:测板子题,分别用Dinic和EK实现(我的板子跑得时间均为0ms). Dinic代码实现如下: #includ ...
- 网络流Dinic算法模板 POJ1273
这就是以后我的板子啦~~~ #include <queue> #include <cstdio> #include <cstring> #include <a ...
- POJ 2987 Firing 最大流 网络流 dinic 模板
https://www.cnblogs.com/137shoebills/p/9100790.html http://poj.org/problem?id=2987 之前写过这道题,码一个dinic的 ...
- 模板——网络流Dinic
感谢这位大佬的博客:https://www.cnblogs.com/SYCstudio/p/7260613.html 给予了我莫大的帮助! 主要说一下网络流的几个注意点: 1.和二分图匹配相似,无法继 ...
- 图论-网络流-Dinic (邻接表版)
//RQ的板子真的很好用 #include<cstdio> #include<cstring> #include<queue> #define INF 1e9 us ...
随机推荐
- const成员函数返回*this
#include <iostream> using namespace std; class A{ public: A &set(char); const A &displ ...
- JAVA初学者——Hello,World!
大家好,我是浩宇大熊猫 我本科专业学的是GIS(Geographical Information System),大学期间也学习了很多的编程语言,有C/C++/JAVA等 之前给我们授课的是韩冰老师, ...
- {转} 深入理解 HTTP Session
session在web开发中是一个非常重要的概念,这个概念很抽象,很难定义,也是最让人迷惑的一个名词,也是最多被滥用的名字之一,在不同的场合,session一次的含义也很不相同.这里只探讨HTTP S ...
- Bugku web(1—35)
1.web2 打开网页: 哈哈,其实按下F12你就会发现flag. 2.计算器 打开网页,只是让你输入计算结果,但是发现只能输入一个数字,这时按下F12,修改一下参数,使之可以输入多个数字,修改后输入 ...
- Unity使用TUIO协议接入雷达
本篇文章不介绍Unity.TUIO.雷达是什么以及有什么作用.刚接触TUIO的亲们,建议直接硬刚.至于刚接触Unity的亲,这边建议亲直接放弃治疗呢 下面开始正儿八经的教程 需要准备的东西 Unity ...
- h5-圆角的使用-案例安卓机器人
1.圆角的使用 <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...
- 【WPF学习】第三十七章 触发器
WPF中有个主题,就是以声明方式扩展代码的功能.当使用样式.资源或数据绑定时,将发现即使不使用代码,也能完成不少工作. 触发器是另一个实现这种功能的例子.使用触发器,可自动完成简单的样式改变,而这通常 ...
- delphi控制word 标题 字符和位置
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...
- pyQt 流布局的一个例子
瀑布流布局 from PyQt5.QtCore import QPoint, QRect, QSize, Qt from PyQt5.QtWidgets import (QApplication, Q ...
- matlab画图中的坐标轴设置
ax = gca; ax是个结构体,查看ax变量,可以看到所有可设置的属性.几个常见属性如下: 设置坐标轴字体大小,粗细,字体名 2014b之后版本: ax = gca; ax.FontSize = ...