Drainage Ditches(dinic)
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 59210 | Accepted: 22737 |
Description
Farmer John knows not only how many gallons of water each ditch can transport per minute but also the exact layout of the ditches, which feed out of the pond and into each other and stream in a potentially complex network.
Given all this information, determine the maximum rate at which water can be transported out of the pond and into the stream. For any given ditch, water flows in only one direction, but there might be a way that water can flow in a circle.
Input
Output
Sample Input
5 4
1 2 40
1 4 20
2 4 20
2 3 30
3 4 10
Sample Output
50
Source
#include<stdio.h>
#include<string.h>
#include<queue>
#include<algorithm>
using namespace std;
const int M = , inf = 0x3f3f3f3f ;
int m , n ;
int map[M][M] ;
int dis[M]; bool bfs ()
{
queue <int> q ;
while (!q.empty ())
q.pop () ;
memset (dis , 0xff , sizeof(dis)) ;
dis[] = ;
q.push () ;
while (!q.empty () ) {
int u = q.front () ;
q.pop () ;
for (int v = ; v <= n ; v++) {
if (map[u][v] && dis[v] == -) {
dis[v] = dis[u] + ;
q.push (v) ;
}
}
}
if (dis[n] > )
return true ;
return false ;
} int find (int u , int low)
{
int a = ;
if (u == n)
return low ;
for (int v = ; v <= n ; v++) {
if (map[u][v] && dis[v] == dis[u] + && (a = find (v , min(map[u][v] , low)))) {
map[u][v] -= a ;
map[v][u] += a ;
return a ;
}
}
return ;
} int main ()
{
// freopen ("a.txt" , "r" , stdin) ;
int u , v , w ;
int ans ;
while (~ scanf ("%d%d" , &m , &n)) {
memset (map , , sizeof(map)) ;
// printf ("m = %d , n = %d\n" , m , n) ;
while (m--) {
scanf ("%d%d%d" , &u , &v , &w) ;
map[u][v] += w ;
}
int maxn = ;
while (bfs()) {
if (ans = find( , inf))
maxn += ans ;
}
printf ("%d\n" , maxn) ;
}
return ;
}
标准的dinic模板
Drainage Ditches(dinic)的更多相关文章
- 【POJ 1273】Drainage Ditches(网络流)
一直不明白为什么我的耗时几百毫秒,明明差不多的程序啊,我改来改去还是几百毫秒....一个小时后:明白了,原来把最大值0x3f(77)取0x3f3f3f3f就把时间缩短为16ms了.可是为什么原来那样没 ...
- 图论-网络流-最大流--POJ1273Drainage Ditches(Dinic)
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 91585 Accepted: 3549 ...
- POJ1273 Drainage Ditches (网络流)
Drainage Ditches Time Limit: 1000MS Memor ...
- HDU 1532 Drainage Ditches (网络流)
A - Drainage Ditches Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64 ...
- [Poj1273]Drainage Ditches(网络流)
Description 给图,求最大流 最大流模板题,这里用dinic Code #include <cstdio> #include <cstring> #include & ...
- POJ1273&&Hdu1532 Drainage Ditches(最大流dinic) 2017-02-11 16:28 54人阅读 评论(0) 收藏
Drainage Ditches Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- poj 1273 Drainage Ditches(最大流)
http://poj.org/problem?id=1273 Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Subm ...
- POJ 1273 Drainage Ditches(网络流,最大流)
Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover ...
- HDU 1532||POJ1273:Drainage Ditches(最大流)
pid=1532">Drainage Ditches Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/327 ...
随机推荐
- 34 Sources for Test Ideas
We recommend collecting test ideas continuously from a variety of information sources. Consider the ...
- 微信小程序剖析【下】:运行机制
在上一篇<微信小程序「官方示例代码」浅析[上]>中,我们只是简单的罗列了一下代码,这一篇,让我们来玩点刺激的——就是看看IDE的代码,了解它是怎么运行的. 还好微信的开发团队在软件工程的实 ...
- C#中的yield return与Unity中的Coroutine(协程)(下)
Unity中的Coroutine(协程) 估计熟悉Unity的人看过或者用过StartCoroutine() 假设我们在场景中有一个UGUI组件, Image: 将以下代码绑定到Image using ...
- [C#]MemoryStream.Dispose之后,为什么仍可以ToArray()?
目录 概述 MemoryStream分析 总结 概述 事件起因,一哥们在群里面贴出了类似下面这样的一段代码: class Program { static void Main(string[] arg ...
- Bootstrap3.0学习第十二轮(导航、标签、面包屑导航)
详情请查看http://aehyok.com/Blog/Detail/18.html 个人网站地址:aehyok.com QQ 技术群号:206058845,验证码为:aehyok 本文文章链接:ht ...
- 2016 版 Laravel 系列入门教程(一)【最适合中国人的 Laravel 教程】
本教程示例代码见: https://github.com/johnlui/Learn-Laravel-5 在任何地方卡住,最快的办法就是去看示例代码. 本文基于 Laravel 5.2 版本,无奈 5 ...
- Go语言_时间篇
Go的time包是标准库中的包之一 不用说,几乎是开发必须用到的包之一.time包的说明文档在: http://golang.org/pkg/time/ 先注意下Overview中的一句话: The ...
- Go-MySQL-Driver:一个Go语言的轻量级极速的mysql驱动
Go语言的 database/sql 包的一个 MySQL驱动. 特性 轻量级与快速 原生Go语言,没有C绑定,只有纯Go 没有不安全的操作(类型转换等) 动态处理崩溃的连接 动态连接池 支持大于16 ...
- float,double,decimal使用讨论
注意:有效位:小数点前后的全部数字,不包括小数点在内 float:浮点型,含字节数为4,32bit,数值范围为-3.4E38~3.4E38(7个有效位) double:双精度实型,含字节数为8,64b ...
- Threat Risk Modeling Learning
相关学习资料 http://msdn.microsoft.com/en-us/library/aa302419(d=printer).aspx http://msdn.microsoft.com/li ...