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 ...
随机推荐
- JavaScript原型与原型链学习笔记
一.什么是原型?原型是一个对象,其他对象可以通过它实现属性继承.简单的说就是任何一个对象都可以成为原型 prototype属性: 我们创建的每个函数都有一个prototype属性,这个属性是一个指针, ...
- 老陈 ASP.NET封装
第一个页面 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data ...
- poj 1815 Friendship 字典序最小+最小割
题目链接:http://poj.org/problem?id=1815 In modern society, each person has his own friends. Since all th ...
- Leetcode#140 Word Break II
原题地址 动态规划题 令s[i..j]表示下标从i到j的子串,它的所有分割情况用words[i]表示 假设s[0..i]的所有分割情况words[i]已知.则s[0..i+1]的分割情况words[i ...
- [错误代码:0x80070002]IIS7及以上伪静态报错404
故障现象:DTCMS开启伪静态功能,VS2010预览正常,发布到IIS后报错404.0错误 (WIN7,WIN8,SERVER2008).模块IISWebCore通知MapRequestHandler ...
- JS设计模式——5.单体模式
JS设计模式——5.单体模式 http://www.cnblogs.com/JChen666/p/3610585.html 单体模式的优势 用了这么久的单体模式,竟全然不知!用它具体有哪些好处呢? ...
- WPF命令参数CommandParameter
XAML代码如下: <Window x:Class="Demo006.MainWindow" xmlns="http://schemas.microsoft.com ...
- windows phone MVVM开发心得第一天
之前刚刚学了asp.net网站的三层架构,为其中的优点着迷,可惜寒假本来决定学下MVC的计划泡汤了,刚开学,学了下windows phone 的MVVM模式的开发,在此留下点心得和脚印,第一天只是学了 ...
- Python:Python 3.x 的革新
Python 3.x 版本在设计时为了向最好的语言前进,没有考虑向下兼容,许多针对早期 Python 版本设计的程序都无法正常运行.本文简单介绍了 Python 3.x 版本较之 2.x 版本语法上的 ...
- 你必须知道的ADO.NET
原文:http://www.cnblogs.com/liuhaorain/archive/2012/02/06/2340409.html 1. 什么是ADO.NET? 简单的讲,ADO.NET是一组允 ...