#include <iostream>
#include <queue>
#include <string.h>
#define MAX 302 using namespace std; int c[MAX][MAX];
int pre[MAX];
int visited[MAX];
int n, m; bool Path(int src, int des)
{
queue <int> q; for (int i = ; i <= m; i++)
{
visited[i] = ;
pre[i] = ;
} q.push(src);
visited[src] = ; while (!q.empty())
{
int cur = q.front();
q.pop(); for (int i = ; i <= m; i++)
{
if (!visited[i] && c[cur][i])
{
q.push(i);
pre[i] = cur;
visited[i] = ;
if (i == des)
{
return true;
break;
}
}
}
}
return false;
} int EK(int src, int des)
{
int min, i, total = ; while (true)
{
if (!Path(src, des))
{
break;
} i = des;
min = ( << );
while (i != src)
{
if (min > c[pre[i]][i])
{
min = c[pre[i]][i];
}
i = pre[i];
} i = des;
while (i != src)
{
c[pre[i]][i] -= min;
c[i][pre[i]] += min;
i = pre[i];
} total += min;
} return total;
}
int main()
{
int a, b, f;
while (cin >> n >> m)
{
memset(c, , sizeof(c));
for (int i = ; i < n; i++)
{
cin >> a >> b >> f;
c[a][b] += f;
} cout << EK(, m) << endl;
}
return ;
}

网络流的EK算法,主要就是不断的找增广路,如果找到了增广路,说明流量还可以增加,否则输出最大流即可.

找增广路用到bfs,找到后必须更新残量网络,用增广路的最大流更新残量网络.

网络流EK的更多相关文章

  1. POJ 1459 网络流 EK算法

    题意: 2 1 1 2 (0,1)20 (1,0)10 (0)15 (1)20 2 1 1 2 表示 共有2个节点,生产能量的点1个,消耗能量的点1个, 传递能量的通道2条:(0,1)20 (1,0) ...

  2. 初涉网络流[EK&dinic]

    主要还是板子 Edmonds-Karp 从S开始bfs,直到找到一条到达T的路径后将该路径增广,并重复这一过程. 在处理过程中,为了应对“找到的一条路径把其他路径堵塞”的情况,采用了建反向弧的方式来实 ...

  3. 最大网络流 EK 算法

    网络流是什么类型的问题,看一道题目你就知道了 点击打开链接 . 默认具备图论的基本知识,网络流概念比较多,先看看书熟悉一下那些概念.比较好!一个寄出的网络最大流.EK算法写的. 这是一幅网络,求S   ...

  4. POJ1149_PIGS(网络流/EK)

    PIGS Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 15721   Accepted: 7021 Description ...

  5. 网络流EK算法模板

    \(EK\)算法的思想就是每一次找一条增广路进行增广. 注意几个点: 存图时\(head\)数组要设为\(-1\). 存图的代码是这样的: inline void add(int u, int v, ...

  6. HDU1532 Drainage Ditches 网络流EK算法

    Drainage Ditches Problem Description Every time it rains on Farmer John's fields, a pond forms over ...

  7. 2016计蒜之道复赛 菜鸟物流的运输网络 网络流EK

    题源:https://nanti.jisuanke.com/t/11215 分析:这题是一个比较经典的网络流模型.把中间节点当做源,两端节点当做汇,对节点进行拆点,做一个流量为 22 的流即可. 吐槽 ...

  8. 网络流 ek

    hdu3549 求最大流果题 ek算法 先bfs出一条流 然后通过不断地添加增广路 得到最大流(证明在算法书上都有) 增加了一个流 就加反向边 允许程序通过走方向边的方式进行“回滚” i^1 = i+ ...

  9. POJ-3436 ACM Computer Factory(网络流EK)

    As you know, all the computers used for ACM contests must be identical, so the participants compete ...

随机推荐

  1. 使用SVN时出现的文件缺失问题

    使用SVN的童鞋们,可能有三种提交代码的方法: 第一种使用客户端(例如SVNX,CornerStone): 第二种使用Xcode提交(Source Control -> commit): 第三种 ...

  2. linux服务器TCP并发连接数优化

    1.查看用户单一进程最大文件打开数 [root@localhost ~]# ulimit -n 1024 2.修改/etc/security/limits.conf文件,添加下面两行, [root@l ...

  3. PHP移动文件指针ftell()、fseek()、rewind()总结

    在对文件进行读写过程中,有时需要在文件中跳转.同不同位置读取,以及将数据写入到不同的位置.例如,使用文件模拟数据库保存数据,就需要移动文件指针.指针的位置是以从文件头开始的字节数度量的,默认以不同模式 ...

  4. PHP-redis中文文档介绍(转自http://www.jb51.net/article/33887.htm)

    Redis::__construct构造函数$redis = new Redis(); connect, open 链接redis服务参数host: string,服务地址port: int,端口号t ...

  5. Lua 单例类

    function SingleTon:new() local store = nil return function(self) if store then return store end loca ...

  6. Python 基本语法 学习之路(三)

    定义变量 在Python中,定义一个变量是很简单的.而且,在Python中,定义是不需要用分号结尾的.例如: a = 10 b = 3 print(a*b) 判断语句 Pyhon的if判断语句是由if ...

  7. service XXX does not support chkconfig

    有时候为了方便管理,我们常常喜欢在Linux中将之安装为服务,然后就可以使用服务来管理. 但是当我们运行安装服务的命令时候,假设服务名为myservice #chkconfig --add myser ...

  8. Spring 4 官方文档学习 Spring与Java EE技术的集成

    本部分覆盖了以下内容: Chapter 28, Remoting and web services using Spring -- 使用Spring进行远程和web服务 Chapter 29, Ent ...

  9. RSpec shared examples with template methods

    It’s pretty common to have multiple tests that are nearly the same. In one app, we support bidding o ...

  10. NABCD

    1) N (Need 需求) 随着科学技术的进步和计算机行业的迅速发展,人们的工作效率得到大大提高.计算机信息处理系统的引进已彻底改变了许多系统的经营管理. 图书管理系统是学校管理机制中的重要组成部分 ...