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 ...
随机推荐
- WEB实时聊天 comet推技术
转自:http://www.cnblogs.com/wodemeng/archive/2012/04/06/2435302.html 今天晚上朋友遇到web服务端推技术的问题,自己就查了下资料,学习了 ...
- android 开发 drawerlayout出现退不回去的情况
问题原因: id_framelayout2 写在 id_linearlayout2 的后面了: 注意记得写: android:layout_gravity="start" 正确: ...
- SharedPreferences实现记住密码功能
SharedPerferences 简单介绍 用于保存简单的键值对数据: 它将数据放在 /data/data/<package name>/shared_prefs目录下,用xml文件保存 ...
- oracle数据库登录连接很慢;kettle连接oracle 报 IO 错误,socket time out 问题解决记录
问题描述: 1:oracle数据库连接登陆时突然变得很慢:sqldeveloper链接数据库很慢: 2:Kettle-spoon etl程序访问数据库,任务执行时报 :数据库连接 IO错误 :Sock ...
- transitionend 事件的兼容
google :webkitTransitionEnd firefox :transitionend ie : MSTransitionEnd
- curl Protocol 'http not supported or disabled in libcurl
C:\Documents and Settings\ganiks.liu\Desktop\curl-7.37.0-win32\bin>curl -V curl 7.37.0 (i386-pc-w ...
- 对git认识
Github则是一个基于Git的日益流行的开源项目托管库.它的使用流程不需要联机,可以先将对代码的修改,评论,保存在本机.等上网之后,再实时推送过去.同时它创建分支与合并分支更容易,推送速度也更快,配 ...
- C# Winform常见的Editor及其它经验
1.新建一个自定义Editor,继承自.NET自带的Editor,override某些方法,再附加到属性中: public class MyCollectionEditor : CollectionE ...
- NumPy的array
1.numpy包中的array数组,用于弥补列表可以存储任意的数据类型的不足,因为有时候我们需要存储某种类型的数据在数组中,这才是数组的本来内涵.我们通过向numpy.array()函数中传递pyth ...
- (转)約瑟夫問題的兩個O(log n)解法
約瑟夫問題的兩個O(log n)解法 這個是學習編程時的一個耳熟能詳的問題了: n個人(編號爲0,1,...,n-1)圍成一個圈子,從0號開始依次報數,每數到第m個人,這個人就得自殺, 之後從下個人開 ...