标准大白书式模板,代码简单但由于效率并不高,所以并不常用,就是这样

 #include<stdio.h>
#include<string.h>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
const int maxm=+;
const int INF=0x3f3f3f3f; struct edge{
int from,to,c,f;
edge(int a,int b,int m,int n):from(a),to(b),c(m),f(n){}
}; struct ek{
int n,m;
vector<edge>e;
vector<int>g[maxm];
int a[maxm];
int p[maxm]; void init(int n){
for(int i=;i<n+;i++)g[i].clear();
e.clear();
} void add(int from,int to,int c){
e.push_back(edge(from,to,c,));
e.push_back(edge(to,from,,));
m=e.size();
g[from].push_back(m-);
g[to].push_back(m-);
} int mf(int s,int t){
int f=;
while(){
memset(a,,sizeof(a));
queue<int>q;
q.push(s);
a[s]=INF;
while(!q.empty()){
int u=q.front();
q.pop();
for(int i=;i<g[u].size();i++){
edge tmp=e[g[u][i]];
if(!a[tmp.to]&&tmp.c>tmp.f){
p[tmp.to]=g[u][i];
a[tmp.to]=min(a[u],tmp.c-tmp.f);
q.push(tmp.to);
}
}
if(a[t])break;
}
if(!a[t])break;
for(int i=t;i!=s;i=e[p[i]].from){
e[p[i]].f+=a[t];
e[p[i]^].f-=a[t]; }
f+=a[t];
}
return f;
}
};

网络流--最大流ek模板的更多相关文章

  1. 网络流--最大流--EK模板

    #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #i ...

  2. (通俗易懂小白入门)网络流最大流——EK算法

    网络流 网络流是模仿水流解决生活中类似问题的一种方法策略,来看这么一个问题,有一个自来水厂S,它要向目标T提供水量,从S出发有不确定数量和方向的水管,它可能直接到达T或者经过更多的节点的中转,目前确定 ...

  3. 网络流--最大流dinic模板

    标准的大白书式模板,除了变量名并不一样……在主函数中只需要用到 init 函数.add 函数以及 mf 函数 #include<stdio.h> //差不多要加这么些头文件 #includ ...

  4. 网络流 最大流SAPkuangbin模板

    hdu 1532 求1~n的最大流 #include<stdio.h> #include<string.h> #include<algorithm> #includ ...

  5. 网络流-最大流 Dinic模板

    #include <bits/stdc++.h> using namespace std; #define MP make_pair #define PB push_back #defin ...

  6. 网络流--最大流--Dinic模板矩阵版(当前弧优化+非当前弧优化)

    //非当前弧优化版 #include <iostream> #include <cstdio> #include <math.h> #include <cst ...

  7. HDU1532 网络流最大流【EK算法】(模板题)

    <题目链接> 题目大意: 一个农夫他家的农田每次下雨都会被淹,所以这个农夫就修建了排水系统,还聪明的给每个排水管道设置了最大流量:首先输入两个数n,m ;n为排水管道的数量,m为节点的数量 ...

  8. HDU1532_Drainage Ditches(网络流/EK模板/Dinic模板(邻接矩阵/前向星))

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

  9. [POJ1273][USACO4.2]Drainage Ditches (网络流最大流)

    题意 网络流最大流模板 思路 EK也不会超时 所以说是一个数据比较水的模板题 但是POJ有点坑,多组数据,而且题目没给 哭得我AC率直掉 代码 用的朴素Dinic #include<cstdio ...

随机推荐

  1. checklistbox的用法

    一般认为:foreach (object obj in checkedListBox1.SelectedItems)即可遍历选中的值.其实这里遍历的只是高亮的值并不是打勾的值.遍历打勾的值要用下面的代 ...

  2. [Java学习] Java虚拟机(JVM)以及跨平台原理

    相信大家已经了解到Java具有跨平台的特性,可以“一次编译,到处运行”,在Windows下编写的程序,无需任何修改就可以在Linux下运行,这是C和C++很难做到的. 那么,跨平台是怎样实现的呢?这就 ...

  3. [Java学习] Java super关键字

    super 关键字与 this 类似,this 用来表示当前类的实例,super 用来表示父类. super 可以用在子类中,通过点号(.)来获取父类的成员变量和方法.super 也可以用在子类的子类 ...

  4. IE6不兼容postion:fixed已解决

    将要设置postion:fixed的元素的css中添加以下代码: //如果想要是头部悬停,则以下代码即可. .customService{        position: fixed;bottom: ...

  5. windows socket网络编程资料汇集

    windows socket网络基础详解(socket的流程介绍的很详细)http://blog.csdn.net/ithzhang/article/details/8448655 Windows S ...

  6. POJ-3087 Shuffle'm Up (模拟)

    Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuff ...

  7. spring-mvc----数据库数据到页面错误--tomcat启动不了

    spring-mvc----数据库数据到页面错误 错误为: 解决: 开启管理员cmd.到tomcat的目录下,-->shutdown.bat 不用重启,不用关机.

  8. Python的数据类型2列表

    Python的数值类型List,也就是列表 Python的列表比较类似与其他语言的数组概念,但他又与其他语言数组的概念有很大的不同 C语言.Java的数组定义是这样的,存储多个同类型的数值的集合就叫数 ...

  9. 蓝桥杯—ALGO-122 未名湖畔的烦恼(枚举)

    问题描述 每年冬天,北大未名湖上都是滑冰的好地方.北大体育组准备了许多冰鞋,可是人太多了, 每天下午收工后,常常一双冰鞋都不剩. 每天早上,租鞋窗口都会排起长龙,假设有还鞋的m个,有需要租鞋的n个. ...

  10. 新手也能学会本地调试微信,natapp 官网映射

    本地调试微信的新手指引~ 照着配置,一定可以配置成功,实现本地调试微信,公司好几个同事按照我写的步骤,都独立配成功了. 1.首选在natapp注册一个账号,申请免费隧道或者购买隧道,我买了一个月9元的 ...