Drainage Ditches

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 8861    Accepted Submission(s): 4141

Problem 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
 

题意不说了,这是网络流经典入门题,最大的坑就是,在最短路题目里面,重边取最小,在网络流里面,重边就相加

WA了N次,才发现这个严重的问题

#include<cstdio>
#include<cstring>
#include<limits.h>
#define min(a,b) a>b?b:a
using namespace std;
int mi[35][5];
int vis[10005];
int m;
int g[1005][1005];
int dfs(int si,int ti,int f)
{
if(si==ti) return f;
vis[si] = 1;
for(int i=1;i<=m;i++)
{
if(!vis[i] && g[si][i]>0)
{
int d = dfs(i,ti,min(f,g[si][i]));
if(d)
{
g[si][i]-=d;
g[i][si]+=d;
return d;
}
}
}
return 0;
} int find(int s, int t)
{
int res = 0;
for(;;)
{
memset(vis,0,sizeof(vis));
int f;
f = dfs(s,t,INT_MAX);
if(f==0) return res;
res+=f;
}
}
int main()
{
int a, b, c;
int n;
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(g,0,sizeof(g));
for(int i=1;i<=n;i++)
{
scanf("%d%d%d",&a,&b,&c);
g[a][b] += c;
}
printf("%d\n",find(1,m));
}
return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

HDU 1532 Drainage Ditches 分类: Brush Mode 2014-07-31 10:38 82人阅读 评论(0) 收藏的更多相关文章

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

  2. HDU 1272 小希的迷宫(并查集) 分类: 并查集 2015-07-07 23:38 2人阅读 评论(0) 收藏

    Description 上次Gardon的迷宫城堡小希玩了很久(见Problem B),现在她也想设计一个迷宫让Gardon来走.但是她设计迷宫的思路不一样,首先她认为所有的通道都应该是双向连通的,就 ...

  3. 全面解析sizeof(下) 分类: C/C++ StudyNotes 2015-06-15 10:45 263人阅读 评论(0) 收藏

    以下代码使用平台是Windows7 64bits+VS2012. sizeof作用于基本数据类型,在特定的平台和特定的编译中,结果是确定的,如果使用sizeof计算构造类型:结构体.联合体和类的大小时 ...

  4. 全面解析sizeof(上) 分类: C/C++ StudyNotes 2015-06-15 10:18 188人阅读 评论(0) 收藏

    以下代码使用平台是Windows7 64bits+VS2012. sizeof是C/C++中的一个操作符(operator),其作用就是返回一个对象或者类型所占的内存字节数,使用频繁,有必须对齐有个全 ...

  5. MS SQL 合并结果集并求和 分类: SQL Server 数据库 2015-02-13 10:59 92人阅读 评论(0) 收藏

    业务情景:有这样一张表:其中Id列为表主键,Name为用户名,State为记录的状态值,Note为状态的说明,方便阅读. 需求描述:需要查询出这样的结果:某个人某种状态的记录数,如:张三,待审核记录数 ...

  6. Optimal Milking 分类: 图论 POJ 最短路 查找 2015-08-10 10:38 3人阅读 评论(0) 收藏

    Optimal Milking Time Limit: 2000MS Memory Limit: 30000K Total Submissions: 13968 Accepted: 5044 Case ...

  7. 菜鸟学习-C语言函数参数传递详解-结构体与数组 分类: C/C++ Nginx 2015-07-14 10:24 89人阅读 评论(0) 收藏

    C语言中结构体作为函数参数,有两种方式:传值和传址. 1.传值时结构体参数会被拷贝一份,在函数体内修改结构体参数成员的值实际上是修改调用参数的一个临时拷贝的成员的值,这不会影响到调用参数.在这种情况下 ...

  8. Nginx介绍 分类: Nginx 服务器搭建 2015-07-13 10:50 19人阅读 评论(0) 收藏

    海量请求,高性能服务器. 对比Apache, Apache:稳定,开源,跨平台,重量级,不支持高度并发的web服务器. 由此,出现了Lighttpd与Nignx:轻量级,高性能. 发音:engine ...

  9. jQuery中的on()和click()的区别 分类: 前端 HTML jQuery 2014-11-06 10:26 96人阅读 评论(0) 收藏

    HTML页面代码 <div> <h1>Click</h1> <button class="add">Click me to add ...

随机推荐

  1. C# Async与Await用法

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  2. ThinkPHP之中的图片上传操作

    直接上个例子,其中包括有单图片文件上传.多图片文件上传.以及删除文件的一些操作.放置删除数据库的时候,仅仅删除掉了数据库之中的文件路径.而不是一并删除服务器之中的文件.放置服务器爆炸... TP里面c ...

  3. Yii中使用PHPExcel导出Excel

    最近在研究PHP的Yii框架,很喜欢,碰到导出Excel的问题,研究了一下,就有了下面的方法: 1.首先在config/main.php中添加对PHPExcel的引用,我的方式是这样: // auto ...

  4. DevExpress 关于 GridView 表格编辑中 点击其他按钮里导致 值未取到处理

    只需要给添加以下代码 在执行其他按钮前调 用一下 就可以了:主要是用来关闭编辑以及更新当前行编辑内容 this.gridControl1.FocusedView.CloseEditor(); this ...

  5. delphi android 中 Toast 的实现(老外写的UNIT)

    unit Android.JNI.Toast; // Java bridge class imported by hand by Brian Long (http://blong.com)interf ...

  6. 学习simple.data之进阶篇

    一.结果排序 -OrderBy(升序) -OrderByDescending(降序) db.Product.All().OrderByFactoryName(); db.Product.All().O ...

  7. 【js & jquery】遮罩层实现禁止a、span、button等元素的鼠标事件

    刚才在写一个界面,其中为了考虑背景图片的缘故,所以没用Button而是用的a标签 在点击之后应该禁用掉a元素,禁用对于button比较容易,加一个disabled就可以了 但是对于a却没有太好的办法, ...

  8. JavaWeb之Servlet:Cookie 和 Session

    会话 现实生活中我们会用手机跟对方对话,拿起手机,拨号,然后对面接听,跟着互相通话,最后会话结束. 这个过程也可以用我们的B/S模式来描述: 打开浏览器—>输入地址->发出请求->服 ...

  9. Sql Server数据的加密与解密

    Sql Server数据的加密与解密 在sql server中,我们如何为数据进行加密与解密,避免使用者窃取机密数据? 对于一些敏感数据,如密码.卡号,一般不能使用正常数值来存储.否则会有安全隐患.以 ...

  10. JavaScript高级程序设计之基本包装类型

    为便于操作基本类型值,ECMAScript提供了3个特殊的引用类型:Boolean, Number 和 String // 字符串怎么会有方法呢 var str1 = "some text& ...