USACO Section 4.2: Drainage Ditches
最大流的模板题
/* ID: yingzho1 LANG: C++ TASK: ditch */ #include <iostream> #include <fstream> #include <string> #include <map> #include <vector> #include <set> #include <algorithm> #include <stdio.h> #include <queue> #include <cstring> #include <cmath> #include <list> #include <cstdio> #include <cstdlib> #include <limits> #include <stack> using namespace std; ifstream fin("ditch.in"); ofstream fout("ditch.out"); ; ; int N, M; int g[MAX][MAX], f[MAX][MAX], pre[MAX], inc[MAX]; bool bfs(int s, int d) { queue<int> que; ; i <= M; i++) pre[i] = -; que.push(s); inc[s] = INF; while (!que.empty()) { int u = que.front(); que.pop(); ; i <= M; i++) { && f[u][i] < g[u][i]) { inc[i] = min(inc[u], g[u][i]-f[u][i]); pre[i] = u; if (i == d) return true; que.push(i); } } } return false; } int edmond_karp(int s, int d) { ; while (bfs(s, d)) { maxflow += inc[d]; for (int i = d; i != s; i = pre[i]) { f[pre[i]][i] += inc[d]; f[i][pre[i]] -= inc[d]; } } return maxflow; } int main() { fin >> N >> M; int s, d, e; ; i < N; i++) { fin >> s >> d >> e; g[s][d] += e; } fout << edmond_karp(, M) << endl; ; }
USACO Section 4.2: Drainage Ditches的更多相关文章
- USACO Section 4.2 Drainage Ditches(最大流)
最大流问题.ISAP算法.注意可能会有重边,不过我用的数据结构支持重边.距离d我直接初始化为0,也可以用BFS逆向找一次. -------------------------------------- ...
- POJ1273 USACO 4.2.1 Drainage Ditches CodeVS1993草地排水 网络流 最大流 SAP
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 传送门 - POJ 传送门 - CodeVS 题意概括 给出一个图,告诉你边和容量,起点是1,汇点是n,让你求最大流. 题解 ...
- USACO 4.2 Drainage Ditches(网络流模板题)
Drainage DitchesHal Burch Every time it rains on Farmer John's fields, a pond forms over Bessie's fa ...
- POJ 1273 Drainage Ditches题解——S.B.S.
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 67823 Accepted: 2620 ...
- poj1273 Drainage Ditches
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 68414 Accepted: 2648 ...
- Drainage Ditches(dinic)
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 59210 Accepted: 2273 ...
- Drainage Ditches
Drainage Ditches Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu-----(1532)Drainage Ditches(最大流问题)
Drainage Ditches Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- POJ 1273 || HDU 1532 Drainage Ditches (最大流模型)
Drainage DitchesHal Burch Time Limit 1000 ms Memory Limit 65536 kb description Every time it rains o ...
随机推荐
- ELK kibana查询与过滤(17th)
在kibana中,可通过搜索查询过滤事务或者在visualization界面点击元素过滤. 创建查询 在Discover界面的搜索栏输入要查询的字段.查询语法是基于Lucene的查询语法.允许布尔运算 ...
- MySQL数据库远程连接开启方法
有时候需要远程连接mysql数据库,默认是不可以的,可以参考下面的方法,解决下. 1.登陆自己机器的MySQL数据库:mysql -uroot -p密码 设置root用户可以任意IP访问,代码如下(可 ...
- sql数据库的表连接方式图文详解
sql数据库表连接,主要分为:内连接.外连接(左连接.右连接 .全连接).交叉连接,今天统一整合一下,看看他们的区别. 首先建表填充值. 学生表:student(id,姓名,年龄,性别 ) 成绩表 ...
- django构建blog--建立数据库部分+admin部分(eclipse+pydev)
本文介绍的是在eclipse+pydev 平台下,利用django 搭建blog的第1部分:建立数据库+admin部分 步骤一:创建myweb项目+blog应用 1. Eclipse下新建一个djan ...
- 迭代启发式搜索 IDA*
本章聚集了一些做了的迭代启发式搜索的题目 为什么只打了迭代启发式搜索? 因为它很好打,有些类似迭代的时候加的最优化剪枝 [因为这个最优化剪枝其实就是你算的估价函数了...] BZOJ 1085 骑士精 ...
- 查看Centos系统信息命令
linux命令行具有强大的功能,我们安装vps后,首先应该知道系统信息,查看这些信息,你会发现Linux命令很简单,你可以按照下面的命令练习. linux系统信息 # uname -a # 查看内核/ ...
- 如何撰写SCI论文的讨论部分?——经典结构 – 俗称“倒漏斗型。
- *args和**kw魔法参数
学Python挺久了,现在才搞懂这个还是有点惭愧 *args:传入元组,无关键字 **kw:传入字典,有关键字 示例: *args **kw 一起使用时args的参数需在前:
- Java中List、Set和Map的区别--转载
List按对象进入的顺序保存对象,不做排序或编辑操作.Set对每个对象只接受一次,并使用自己内部的排序方法(通常,你只关心某个元素是否属于Set,而不关心它的顺序--否则应该使用List).Map同样 ...
- x64 结构体系下的内存寻址
欢迎转载,转载请注明出处:http://www.cnblogs.com/lanrenxinxin/p/4735027.html 在阅读NewBluePill源码的时候,看内存的那一块简直头疼,全是x6 ...