网络流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 ...
随机推荐
- POJ 1651:Multiplication Puzzle 矩阵相乘式DP
Multiplication Puzzle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7118 Accepted: ...
- 洛谷 P5663 加工零件
题目传送门 解题思路: 最暴力的做法: bfs模拟,每次将一个阶段的所有点拿出来,将其所有直连的点都放进队列,知道本阶段结束,最后看1号点会不会在最后一个阶段被放入队列.(洛谷数据40分) 优化了一下 ...
- SpringCloud学习之手把手教你用IDEA搭建入门项目(二)
本篇博客是承接上一篇<手把手教你用IDEA搭建SpringCloud入门项目(一)>,不清楚的请到我的博客空间查看后再看本篇博客 1)先创建一个Eureka服务注册中心模块,用来作为服务的 ...
- 开源PLM软件Aras详解八 Aras之RelationshipTypes关系类详解
在Aras中,在之前ItemType解析中有提到,Aras中实际ItemType对应的就是一张表,那么,ItemType与ItemType之间是如何关联的呢, 如果我们需要捋清楚ItemType与It ...
- {转} 深入理解 HTTP Session
session在web开发中是一个非常重要的概念,这个概念很抽象,很难定义,也是最让人迷惑的一个名词,也是最多被滥用的名字之一,在不同的场合,session一次的含义也很不相同.这里只探讨HTTP S ...
- POJ-2492 A Bug's Life(种类并查集)
http://poj.org/problem?id=2492 题意: 给出一个T代表几组数据,给出一个n一个m,代表人的编号由1~n,m条命令,每条命令由两个数值组成,代表这两个人性别不同,问所有命令 ...
- php://filter(文件包含漏洞利用)及php://input
1. php://filter 文件包含漏洞:https://blog.csdn.net/fageweiketang/article/details/80699051 筛选过滤应用: 1. 字符串过滤 ...
- cpu压测测试--------自己设定cpu需要跑到的压力
下载压力测试包 https://pan.baidu.com/s/1DJYAzBHHDxMViy5dMel2Lw 提取码:a5j3 使用方法: 方法一:前端启动,按Ctrl+c结束 java -Dbus ...
- tensorflow 损失计算--MSN
1.tf.losses.mean_squared_error函数 tf.losses.mean_squared_error( labels, predictions, weights=1.0, sco ...
- 和我一起从0学算法(C语言版)(二)
第一章 排序 第三节 快速排序 快速排序是最常用的排序方法.快排运用的递归方法很有意思.掌握了这种排序方法可以在将来学习递归时更快入门.只是快排的思路与之前的排序方法相比较为复杂,再加担心上我的表达能 ...