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 ...
随机推荐
- 【WildCard Matching】cpp
题目: Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any single charact ...
- [转载]char * 和char []的区别---之第二篇
原文地址:http://blog.sina.com.cn/s/blog_74a4593801019keb.html main() { char *p="abc123ABC";//c ...
- Retry Pattern
Retry Pattern https://msdn.microsoft.com/en-us/library/dn589788.aspx https://msdn.microsoft.com/en-u ...
- 设计模式之状态模式(State)
状态模式原理:随着状态的变化,对象的行为也发生变化 代码如下: #include <iostream> #include <string> #include <list& ...
- Binary Indexed Tree 2D 分类: ACM TYPE 2014-09-01 08:40 95人阅读 评论(0) 收藏
#include <cstdio> #include <cstdlib> #include <climits> #include <cstring> # ...
- NYOJ-206 矩形的个数 AC 分类: NYOJ 2013-12-29 22:19 265人阅读 评论(0) 收藏
这题目是小学奥数题目,方法可以百度到,但是,有个难点就是,数据类型大小不够,如果是1000x1000的矩阵,那么就会超过int的范围,所以,就引进了long long的数据类型 #include< ...
- ubuntu文件定时加密压缩
#!/bin/sh #zip.sh DATE=`date -d yesterday +"%Y%m%d"` #password PASS="123456" if ...
- 使用开关、分段控件和web视图
#import "XViewController.h" @interface XViewController () @end @implementation XViewContro ...
- HDU1004 Let the Balloon Rise(map的简单用法)
Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- JavaScript之Throw、Try 、Catch讲解
try 语句测试代码块的错误. catch 语句处理错误. throw 语句创建自定义错误. 错误一定会发生 当 JavaScript 引擎执行 JavaScript 代码时,会发生各种错误: 可能是 ...