1. //最短增广路,Dinic算法
  2. struct Edge
  3. {
  4. int from,to,cap,flow;
  5. };//弧度
  6.  
  7. void AddEdge(int from,int to,int cap) //增弧
  8. {
  9. edges.push_back((Edge){from,to,cap,});
  10. edges.push_back((Edge){to,from,,});
  11. m=edges.size();
  12. G[from].push_back(m-);
  13. G[to].push_back(m-);
  14. }
  15.  
  16. struct Dinic{
  17. int n,m,s,t;
  18. vector<Edge> edges;
  19. vector<int> G[maxn];
  20. bool vis[maxn];
  21. int d[maxn];
  22. int cur[maxn];
  23.  
  24. bool Bfs() //构建分层网络
  25. {
  26. memset(vis,,sizeof(vis));
  27. queue<int> Q;
  28. Q.push(s);
  29. d[s]=;
  30. vis[s]=;
  31. while(!Q.empty())
  32. {
  33. int x=Q.front();
  34. Q.pop();
  35. for(int i=;i<G[x].size();i++)
  36. Edge& e=edges[G[x][i]];
  37. if(!vis[e.to]&&e.cap>e.flow)
  38. {
  39. vis[e.to]=;
  40. d[e.to]=d[x]+;
  41. Q.push(e.to);
  42. }
  43. }
  44. return vis[t];
  45. }
  46. };
  47.  
  48. int DFS(int x,int a)//沿阻塞流增广
  49. {
  50. if(x==t||a==)
  51. return a;
  52. int flow=,f;
  53. for(int& i=cur[x];i<G[x].size();i++)
  54. {
  55. Edge& e=edges[G[x][i]];
  56. if(d[x]+==d[e.to]&&(f=DFS(e.to,min(a,e.cap-e.flow)))>)
  57. {
  58. e.flow+=f;
  59. edges[G[x][i]^].flow-=f;
  60. flow+=f;
  61. a-=f;
  62. if(a==)
  63. break;
  64. }
  65. }
  66. return flow;
  67. }
  68.  
  69. int Maxflow(int s,int t)
  70. {
  71. this->s=;
  72. this->t=t;
  73. int flow=;
  74. while(BFS())
  75. {
  76. memset(cur,,sizeof(cur));
  77. flow+=DFS(s,inf);
  78. }
  79. return flow;
  80. }

求最大流dinic算法模板的更多相关文章

  1. POJ 1815 - Friendship - [拆点最大流求最小点割集][暴力枚举求升序割点] - [Dinic算法模板 - 邻接矩阵型]

    妖怪题目,做到现在:2017/8/19 - 1:41…… 不过想想还是值得的,至少邻接矩阵型的Dinic算法模板get√ 题目链接:http://poj.org/problem?id=1815 Tim ...

  2. POJ 3469.Dual Core CPU 最大流dinic算法模板

    Dual Core CPU Time Limit: 15000MS   Memory Limit: 131072K Total Submissions: 24830   Accepted: 10756 ...

  3. poj 1273最大流dinic算法模板

    #include<stdio.h> #include<string.h> #define N 300 #define inf 0x7fffffff #include<qu ...

  4. 最大流Dinic算法模板(pascal)

    program rrr(input,output); const inf=; type pointer=^nodetype; nodetype=record t,c:longint; next,rev ...

  5. HDU1532最大流 Edmonds-Karp,Dinic算法 模板

    Drainage Ditches Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...

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

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

  7. hdu 2435 dinic算法模板+最小割性质

    #include<stdio.h> #include<queue> #include<string.h> using namespace std; #define ...

  8. 网络流之最大流Dinic算法模版

    /* 网络流之最大流Dinic算法模版 */ #include <cstring> #include <cstdio> #include <queue> using ...

  9. POJ 1273 - Drainage Ditches - [最大流模板题] - [EK算法模板][Dinic算法模板 - 邻接表型]

    题目链接:http://poj.org/problem?id=1273 Time Limit: 1000MS Memory Limit: 10000K Description Every time i ...

随机推荐

  1. gitlab4.0_安装

    一,安装环境 OS:redhat7.4 二,安装依赖包 yum -y groupinstall 'Development Tools'  ===>待验证 yum -y install pytho ...

  2. sudo安装某一文件报错:E: 无法获得锁 /var/lib/dpkg/lock - open (11: 资源暂时不可用) E: 无法锁定管理目录(/var/lib/dpkg/),是否有其他进程正占用它?

    报错原因:资源被占用 解决方法: sudo rm /var/cache/apt/archives/lock sudo rm /var/lib/dpkg/lock

  3. <<Natural Language Inference over Interaction Space >> 句子匹配

    模型结构 code :https://github.com/YichenGong/Densely-Interactive-Inference-Network 首先是模型图: Embedding Lay ...

  4. sitecore系统教程之内容创作入门

    在Sitecore中,有两种编辑工具,您可以在其中创建和编辑网站上的内容: 内容编辑器 - 专为熟悉Sitecore及其包含的功能的经验丰富的内容作者而设计的应用程序. 体验编辑器 - 一种直观的编辑 ...

  5. Python - 2. Built-in Collection Data Types

    From: http://interactivepython.org/courselib/static/pythonds/Introduction/GettingStartedwithData.htm ...

  6. jQuery工具--$.each()和$.merge()

       jQuery.each(object, [callback])或者jQuery(object).each([callback]) 概述 通用遍历方法,可用于遍历对象和数组. 不同于遍历 jQue ...

  7. sql 表中删除字段重复的行

    Id    Email    UserName1    Taiseer.Joudeh@hotmail.com    TaiseerJoudeh2    Hasan.Ahmad@mymail.com   ...

  8. sqoop使用经验总结及问题汇总

    问题导读1.导入数据到HDFS,需要注意什么?2.在测试sqoop语句的时候,如何限制记录数量?3.sqoop导入时什么情况下会多导入一条数据? 一.sqoop 导入数据到HDFS注意事项 分割符的方 ...

  9. Vue + vant-UI 打造移动商城

  10. Linux基础命令---ifdown、ifup

    ifup ifup指令用来启动网络接口设备,设备必须是定义在“/etc/sysconfig/network-scripts/ifcfg-ethX”或者“/etc/sysconfig/network”的 ...