//Dinic
struct Edge{
int from,to,cap,flow;
Edge(){ }
Edge(int a,int b,int c,int d){
from=a;
to=b;
cap=c;
flow=d;
}
}edges[maxm*];
int n,m,s,t,sz;
vector<int> ve[maxn];
int dis[maxn],cur[maxn];
bool vis[maxn];
int l,r;
void addEdge(int a,int b,int c)
{
edges[sz++]=Edge(a,b,c,);
edges[sz++]=Edge(b,a,,);
ve[a].push_back(sz-);
ve[b].push_back(sz-);
}
bool BFS(){
memset(vis,,sizeof(vis));
queue<int> qu;
qu.push(s);
dis[s]=;
vis[s]=;
while(qu.size()){
int u=qu.front();qu.pop();
for(int i=;i<ve[u].size();i++){
Edge& e=edges[ve[u][i]];
if(!vis[e.to] && e.flow<e.cap){
vis[e.to]=;
qu.push(e.to);
dis[e.to]=dis[u]+;
}
}
}
return vis[t];
}
int DFS(int x,int a)
{
if(x==t || a==)return a;
int flow=,f;
for(int& i=cur[x];i<ve[x].size();i++){
Edge e=edges[ve[x][i]];
if(dis[x]+==dis[e.to] && (f=DFS(e.to,min(a,e.cap-e.flow)))>){
flow+=f;
a-=f;
edges[ve[x][i]].flow+=f;
edges[ve[x][i]^].flow-=f;
if(a==)break;
}
}
return flow;
}
int dinic()
{
int flow=;
while(BFS()){
memset(cur,,sizeof(cur));
flow += DFS(s,);
}
return flow;
}

模板-网络流-Dinic的更多相关文章

  1. 模板——网络流Dinic

    感谢这位大佬的博客:https://www.cnblogs.com/SYCstudio/p/7260613.html 给予了我莫大的帮助! 主要说一下网络流的几个注意点: 1.和二分图匹配相似,无法继 ...

  2. POJ 1273 Drainage Ditches (网络流Dinic模板)

    Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover ...

  3. ACM/ICPC 之 有流量上下界的网络流-Dinic(可做模板)(POJ2396)

    //有流量上下界的网络流 //Time:47Ms Memory:1788K #include<iostream> #include<cstring> #include<c ...

  4. POJ 1273 Drainage Ditches(网络流dinic算法模板)

    POJ 1273给出M条边,N个点,求源点1到汇点N的最大流量. 本文主要就是附上dinic的模板,供以后参考. #include <iostream> #include <stdi ...

  5. POJ 3281 [网络流dinic算法模板]

    题意: 农场主有f种食物,d种饮料,n头牛. 接下来的n行每行第一个数代表第i头牛喜欢吃的食物数量,和第i头牛喜欢喝的饮料数目. 接下来分别是喜欢的食物和饮料的编号. 求解:农场主最多能保证几头牛同时 ...

  6. 网络流dinic ek模板 poj1273

    这里只是用来存放模板,几乎没有讲解,要看讲解网上应该很多吧…… ek bfs不停寻找增广路到找不到为止,找到终点时用pre回溯,O(VE^2) #include<cstdio> #incl ...

  7. Power Network POJ - 1459 网络流 DInic 模板

    #include<cstring> #include<cstdio> #define FOR(i,f_start,f_end) for(int i=f_startl;i< ...

  8. 网络流Dinic模板

    #include <iostream> #include <cstdio> #include <cstring> #include <queue> #d ...

  9. 网络流dinic模板,邻接矩阵+链式前向星

    //这个是邻接矩阵的#include<iostream> #include<queue> #include<string.h> #include<stdio. ...

随机推荐

  1. [洛谷P3693]琪露诺的冰雪小屋

    题目大意:琪露诺的冰雪小屋,我做的第一道大模拟题. 题解:模拟... 卡点:无数小错误,要是没有写一点调一点,那大概是永远调不出来了... C++ Code: #include <cstdio& ...

  2. VS的ncb、pdb文件分析

           原文链接地址:http://blog.csdn.net/changbaolong/article/details/7472685        NCB是"No Compile ...

  3. BZOJ1057 [ZJOI2007]棋盘制作 【最大同色矩形】

    1057: [ZJOI2007]棋盘制作 Time Limit: 20 Sec  Memory Limit: 162 MB Submit: 3248  Solved: 1636 [Submit][St ...

  4. BZOJ3673 & BZOJ3674 可持续化并查集 【可持续化线段树维护可持续化数组】

    题目描述 n个集合 m个操作 操作: 1 a b 合并a,b所在集合 2 k 回到第k次操作之后的状态(查询算作操作) 3 a b 询问a,b是否属于同一集合,是则输出1否则输出0 0 输入格式 输出 ...

  5. CMD批处理把txt文本中的每行写入一个新文件,第一列作文件名

    需求 现在有一个文件格式如图 ID 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17001 89.84 8.87 1.29 -0.0 0.0 68.99 0.0 0. ...

  6. EditPlus直接连接Linux服务器编辑文本文件

    填写好:描述,ip地址,用户名,密码, 然后点下面的高级选项: 然后返回上一个页面,继续 确定 OK: 然后,在主界面左侧点倒三角: 就可以选择我们之前配置的远程服务器地址,弹出提示框 点确定, 就连 ...

  7. Intellij Idea debug 远程部署的的tomcat项目

    web项目部署到tomcat上之后,有时需要打断点单步调试,如果用的是Intellij idea,可以通过如下方法实现: 开启debug端口,启动tomcat 以tomcat7.0.75为例,打开bi ...

  8. 使用 FirewallD 构建动态防火墙

    使用 FirewallD 构建动态防火墙 FirewallD 提供了支持网络/防火墙区域(zone)定义网络链接以及接口安全等级的动态防火墙管理工具.它支持 IPv4, IPv6 防火墙设置以及以太网 ...

  9. MySQL 8.0.11 中使用 grant ... identified by 时 error 1064 near 'identified by '密码'' at line 1

    (1)问题:     当使用 grant 权限列表 on 数据库 to '用户名'@'访问主机' identified by '密码'; 时会出现"......near 'identifie ...

  10. 《vue.js实战》练习---标签页组件

    html: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...