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 ...
随机推荐
- Spring MVC 环境搭建(一)
一.建立 JavaWeb 项目 1.建立一个 Java 项目. 2.在项目下新建一个文件夹 webapp (命名可自取,这个目录即是网站根目录),再在该文件夹下新建一个 WEB-INF 文件夹(命名固 ...
- 《JavaScript高级程序设计》第5章 引用类型
5.2.2 转换方法 所有对象都有toString()和valueOf()方法调用数组的toString()方法,会返回一个字符串,由数组中的每个项通过逗号连接而成调用valueOf()还是返回数组 ...
- EditPlus配置[C++] [Python] [Java] 编译运行环境
以前一直用Codeblocks写C++,eclipse写Java,再在eclipse里面集成PyDev写Python,首先无法忍受代码自动补全功能(这个功能也许你万分喜欢),也无法忍受如此重量级的ID ...
- Discuz! X3.1去除内置门户导航/portal.php尾巴的方法
方法: 打开文件 /source/admincp/admincp_domain.php 查找 [php] if(!empty($domain) && in_array($domain, ...
- UML架构(转载)
任何真正的世界系统是由不同的用户使用.用户可以是开发人员,测试人员,商务人士,分析师和等等.所以在设计一个系统的体系结构是用不同的角度心态.最重要的部分是从不同的观看者的角度来看,以可视化的系统.我们 ...
- 为 PHP 开发者准备的 12 个调试工具
PHP是在实践中发展迅速并被最多使用的脚本语言:包含了诸如详细的文档.庞大的社区.无数可使用的脚本及支持框架等许多特性.PHP提供的这些特性使得它比Python或Ruby等脚本语言更容易上手. 为构建 ...
- Unity3D 使用 Editor 脚本,自定义 脚本的属性面板
1. 先有一个普通的 继承自 MonoBehaviour 的脚本. 2. 创建一个 Editor 文件夹, 写 关于 UnityEditor 的脚本 都要放在这个文件夹下,不然会编译出错. 具体的实现 ...
- HDU 3642 Get The Treasury (线段树扫描线,求体积并)
参考链接 : http://blog.csdn.net/zxy_snow/article/details/6870127 题意:给你n个立方体,求覆盖三次以上(包括三次)的区域的体积 思路:先将z坐标 ...
- POJ 1469
#include<iostream> #include<stdio.h> #include <string.h> #include <vector> # ...
- Quant面试准备5本书
Heard on The Street: Quantitative Questions from Wall Street Job Interviews - Timothy Falcon Crack F ...