Drainage Ditches

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 12771    Accepted Submission(s): 6097

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
 
Source
 

题意:给出n个河流,m个点,以及每个河流的流量,求从1到m点的最大流量。

没啥好说的,裸的最大流,试了一下模板,注意模板的下标。。。

#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
#define ll long long
#define _cle(m, a) memset(m, a, sizeof(m))
#define repu(i, a, b) for(int i = a; i < b; i++)
#define repd(i, a, b) for(int i = b; i >= a; i--)
#define sfi(n) scanf("%d", &n)
#define pfi(n) printf("%d\n", n)
#define sfi2(n, m) scanf("%d%d", &n, &m)
#define pfi2(n, m) printf("%d %d\n", n, m)
#define pfi3(a, b, c) printf("%d %d %d\n", a, b, c)
#define MAXN 105
#define V 55
//const int INF = 0x3f3f3f3f; #define maxn 210
const int inf = 0x3f3f3f3f; struct EK
{
int cap[maxn][maxn];
int flow[maxn][maxn];
int n;
void init(int n)
{
this->n = n;
memset(cap, , sizeof(cap));
}
void addCap(int i, int j, int val)
{
cap[i][j] += val;
}
int solve(int source, int sink)
{
if(source == sink) return inf;///源=汇, 流量无穷大!
static int que[maxn], pre[maxn], d[maxn];
///bfs时的队列; bfs时某点的前驱; 增光路径的流量
int p, q, t;///bfs时的队列底、顶; bfs时当前元素
memset(flow, , sizeof(flow));
while(true)
{
memset(pre, , sizeof(pre));
d[source] = inf;
p = q = ;
que[q++] = source; while(p<q && pre[sink]==-)
{
t = que[p ++];
for(int i = ; i <= n; i ++)
{
if(pre[i]==- && cap[t][i]-flow[t][i]>)
{
///残余=cap-flow
pre[i] = t;
que[q++]=i;
d[i] = min(d[t], cap[t][i]-flow[t][i]);
}
}
//pfi(1000);
}
if(pre[sink]==-) break;///没有增广路径了!
for(int i = sink; i != source; i = pre[i])
{
flow[pre[i]][i] += d[sink];
flow[i][pre[i]] -= d[sink];
}
}
t = ;///当做网络流量
for(int i = ; i <= n; i ++)
{
t += flow[source][i];
//pfi(flow[source][i]);
}
return t;
}
}ek; int main()
{
int n, m;
while(~sfi2(m, ek.n))
{
ek.init(ek.n);
int x, y, z;
repu(i, , m)
{
sfi2(x, y), sfi(z);
ek.addCap(x, y, z);
}
pfi(ek.solve(, ek.n));
}
return ;
}

最新文章

  1. Sql Server系列:Insert语句
  2. SQL Server 2012 学习笔记4
  3. CSS3_loading效果
  4. Mac OS的phpize空信息解决办法
  5. AngularJs的UI组件ui-Bootstrap-Tooltip
  6. 合并JS和CSS
  7. ASP.NET MVC基于标注特性的Model验证:一个Model,多种验证规则
  8. Developing a Custom Membership Provider from the scratch, and using it in the FBA (Form Based Authentication) in SharePoint 2010
  9. [JAVA]JAVA章4 Thread Dump如何分析
  10. STL之Vector容器
  11. vetur插件提示 [vue-language-server] Elements in iteration expect to have &#39;v-bind:key&#39; directives
  12. 微信小程序开发 [03] 事件、数据绑定和传递
  13. 解读ARM成功秘诀:薄利多销推广产品
  14. Android:手把手带你深入剖析 Retrofit 2.0 源码
  15. 转:25个Java机器学习工具和库
  16. 20145234黄斐《Java程序设计》第六周学习总结
  17. mysql int类型的长度值
  18. [洛谷P3332][ZJOI2013]K大数查询
  19. scanf函数用法小记
  20. UOJ67 新年的毒瘤

热门文章

  1. react 年-月-日 时:分:秒
  2. phpstorm-----------如何激活phpstorm2016
  3. Android之ViewHolder用法
  4. JS逗号运算符的用法详解
  5. 161216、使用spring的DefaultResourceLoader自定义properties文件加载工具类
  6. Linux命令学习整理。
  7. jQuery 遍历(上)
  8. python(二)数据类型
  9. python 学习笔记十四 jQuery案例详解(进阶篇)
  10. SQL 向上取整、向下取整、四舍五入取整的实例!round、rounddown、roundup