博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ1273 Drainage Ditches (网络流)
阅读量:5738 次
发布时间:2019-06-18

本文共 2647 字,大约阅读时间需要 8 分钟。

                                                         Drainage Ditches
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 69983   Accepted: 27151

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 41 2 401 4 202 4 202 3 303 4 10

Sample Output

50 【分析】我直接套的树上的网络流标号法模板。
#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define inf 0x3f3f3f3f#define mod 1000000007typedef long long ll;using namespace std;const int N=205;const int M=1005;int s,t,n,m,num,k;int customer[N][N];int flow[N][N];int house[M],last[M];int pre[N],minflow[N];void BFS() { queue
q; int p=0; memset(flow,0,sizeof(flow)); minflow[1]=inf; while(1) { while(!q.empty())q.pop(); for(int i=0; i
=0; j=i,i=pre[i]) { flow[i][j]+=minflow[t]; flow[j][i]=-flow[i][j]; } } for(int i=0; i
View Code

转载于:https://www.cnblogs.com/jianrenfang/p/5826299.html

你可能感兴趣的文章
<context:component-scan>详解
查看>>
DS博客作业07--查找
查看>>
Git 方法
查看>>
[Python] numpy.nonzero
查看>>
2016-11-29
查看>>
C#反射的坑
查看>>
css3 box-shadow阴影(外阴影与外发光)讲解
查看>>
时间助理 时之助
查看>>
nginx快速安装
查看>>
自定义转场动画
查看>>
英国征召前黑客组建“网络兵团”
查看>>
Silverlight 2.5D RPG游戏“.NET技术”技巧与特效处理:(十二)魔法系统
查看>>
[NPM] Run npm scripts in series
查看>>
vs2013修改书签(vs书签文件位置)
查看>>
C语言学习笔记
查看>>
PHP 命令行模式实战之cli+mysql 模拟队列批量发送邮件(在Linux环境下PHP 异步执行脚本发送事件通知消息实际案例)...
查看>>
PS 如何使用液化工具给人物减肥
查看>>
cvc-complex-type.2.4.c: The matching wildcard...
查看>>
android 读取json数据(遍历JSONObject和JSONArray)
查看>>
pyjamas build AJAX apps in Python (like Google did for Java)
查看>>