Drainage Ditches
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 59210   Accepted: 22737

Description

Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover patch. This means that the clover is covered by water for awhile and takes quite a long time to regrow. Thus, Farmer John has built a set of drainage ditches so that Bessie's clover patch is never covered in water. Instead, the water is drained to a nearby stream. Being an ace engineer, Farmer John has also installed regulators at the beginning of each ditch, so he can control at what rate water flows into that ditch. 
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

The input includes several cases. For each case, the first line contains two space-separated integers, N (0 <= N <= 200) and M (2 <= M <= 200). N is the number of ditches that Farmer John has dug. M is the number of intersections points for those ditches. Intersection 1 is the pond. Intersection point M is the stream. Each of the following N lines contains three integers, Si, Ei, and Ci. Si and Ei (1 <= Si, Ei <= M) designate the intersections between which this ditch flows. Water will flow through this ditch from Si to Ei. Ci (0 <= Ci <= 10,000,000) is the maximum rate at which water will flow through the ditch.

Output

For each case, output a single integer, the maximum rate at which water may emptied from the pond.

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)的更多相关文章

  1. 【POJ 1273】Drainage Ditches(网络流)

    一直不明白为什么我的耗时几百毫秒,明明差不多的程序啊,我改来改去还是几百毫秒....一个小时后:明白了,原来把最大值0x3f(77)取0x3f3f3f3f就把时间缩短为16ms了.可是为什么原来那样没 ...

  2. 图论-网络流-最大流--POJ1273Drainage Ditches(Dinic)

    Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 91585   Accepted: 3549 ...

  3. POJ1273 Drainage Ditches (网络流)

                                                             Drainage Ditches Time Limit: 1000MS   Memor ...

  4. HDU 1532 Drainage Ditches (网络流)

    A - Drainage Ditches Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64 ...

  5. [Poj1273]Drainage Ditches(网络流)

    Description 给图,求最大流 最大流模板题,这里用dinic Code #include <cstdio> #include <cstring> #include & ...

  6. 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) ...

  7. poj 1273 Drainage Ditches(最大流)

    http://poj.org/problem?id=1273 Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Subm ...

  8. POJ 1273 Drainage Ditches(网络流,最大流)

    Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover ...

  9. HDU 1532||POJ1273:Drainage Ditches(最大流)

    pid=1532">Drainage Ditches Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/327 ...

随机推荐

  1. html的转码玉反转码

    function HTMLEncode(html) { var temp = document.createElement ("div"); (temp.textContent ! ...

  2. VS2010版快捷键

    VS2010版快捷键 Ctrl+E,D ----格式化全部代码 Ctrl+E,F ----格式化选中的代码 CTRL + SHIFT + B生成解决方案 CTRL + F7 生成编译 CTRL + O ...

  3. Lambda表达式和表达式树

    在C# 2.0中,通过方法组转换和匿名方法,使委托的实现得到了极大的简化.但是,匿名方法仍然有些臃肿,而且当代码中充满了匿名方法的时候,可读性可能就会受到影响.C# 3.0中出现的Lambda表达式在 ...

  4. Hibernate-一级缓存session

    hibernate提供的一级缓存 hibernate是一个线程对应一个session,一个线程可以看成一个用户.也就是说session级缓存(一级缓存)只能给一个线程用,别的线程用不了,一级缓存就是和 ...

  5. Java基础-四要素之一《继承》

    继承的概念: 继承在本职上是特殊——一般的关系,即常说的is-a关系.子类继承父类,表明子类是一种特殊的父类,并且具有父类所不具有的一些属性或方法. 继承是所有OOP语言不可缺少的部分,在java中使 ...

  6. hasSet,TreeSet,ArrayList,LinkedList,Vector,HashMap,HashTable,TreeMap利用Iterator进行输出

    基础类,没有重写hashCode()和equals()方法: package niukewang; import java.util.Objects; public class setClass { ...

  7. 10 个免费的 jQuery 可视化编辑器插件

    富文本编辑器,也就是所见即所得的 HTML 编辑器,是网站一个非常重要的组件,特别是对于一些内容发布网站来说.本文介绍 10 个基于 jQuery 的可视化文本编辑器. MarkitUp markIt ...

  8. 【UVA 11401】Triangle Counting

    题 题意 求1到n长度的n根棍子(3≤n≤1000000)能组成多少不同三角形. 分析 我看大家的递推公式都是 a[i]=a[i-1]+ ((i-1)*(i-2)/2-(i-1)/2)/2; 以i 为 ...

  9. request.getAttribute() 和 request.getParameter() 有何区别?

    HttpServletRequest类既有getAttribute()方法,也由getParameter()方法,这两个方法有以下区别: (1)HttpServletRequest类有setAttri ...

  10. 【BZOJ-3651&3081】网络通信&StrangeRegulations Link-Cut-Tree

    3651: 网络通信 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 90  Solved: 61[Submit][Status][Discuss] D ...