hdu1532Drainage Ditches(最大流)
来源:互联网 发布:淘宝双十一怎么报名 编辑:程序博客网 时间:2024/06/05 14:24
Drainage Ditches
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 6743 Accepted Submission(s): 3195
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.
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.
#include <iostream>#include <queue>#include <string.h>#define MAX 302using namespace std;int c[MAX][MAX];int pre[MAX];int visited[MAX];int n, m;bool Path(int src, int des){ queue <int> q; for (int i = 0; i <= m; i++) { visited[i] = 0; pre[i] = 0; } q.push(src); visited[src] = 1; while (!q.empty()) { int cur = q.front(); q.pop(); for (int i = 1; i <= m; i++) { if (!visited[i] && c[cur][i]) { q.push(i); pre[i] = cur; visited[i] = 1; if (i == des) { return true; break; } } } } return false;}int EK(int src, int des){ int min, i, total = 0; while (true) { if (!Path(src, des)) { break; } i = des; min = (1 << 30); while (i != src) { if (min > c[pre[i]][i]) { min = c[pre[i]][i]; } i = pre[i]; } i = des; while (i != src) { c[pre[i]][i] -= min; c[i][pre[i]] += min; i = pre[i]; } total += min; } return total;}int main(){ int a, b, f; while (cin >> n >> m) { memset(c, 0, sizeof(c)); for (int i = 0; i < n; i++) { cin >> a >> b >> f; c[a][b] += f; } cout << EK(1, m) << endl; } return 0;}
- hdu1532Drainage Ditches(最大流)
- hdu1532Drainage Ditches 最大流模板水题
- HDU1532Drainage Ditches(网络流Ford-Fulkerson模板)
- hdu1532Drainage Ditches裸的网络流
- (最大流)Drainage Ditches(P1273)
- HDOJ 1532 Drainage Ditches(最大流)
- Drainage Ditches (最大流问题)
- poj - 1273 - Drainage Ditches(最大流)
- poj1273--Drainage Ditches(最大流)
- HDU 1532 Drainage Ditches(最大流)
- HDU1532 Drainage Ditches(最大流)
- poj 1273 Drainage Ditches(最大流)
- HDU 1532 Drainage Ditches(最大流)
- poj1273 Drainage Ditches(最大流)
- hdu1532 Drainage Ditches(最大流)
- poj--1237--Drainage Ditches(最大流)
- POJ1273 Drainage Ditches(最大流)
- POJ-1273 Drainage Ditches(最大流)
- 金额单位的转换
- 原生JavaScript技巧大收集(31~40)移动篇
- DataGridView中对各种类型的单元格控件的事件处理(DataGridViewCheckBoxCell、DataGridViewComboBoxCell等的选定、事件触发)
- 小菜鸟 学MQ(二)
- Android虚拟机不允许单个程序中的Bitmap占用超过8M的内存
- hdu1532Drainage Ditches(最大流)
- 公益讲座:开源力量公开课
- 开源力量公开
- Picture(hdu1828,求周长并,线段树+离散化+扫描)
- oracle怎样将Scott中的表和记录copy到新建用户
- android内存优化之图片优化
- Xcode 中的Bundle versions string, short 和 Bundle version 区别
- 人脸识别——浙大 何晓飞 主页
- 文本框(Textbox)和下拉框(Combobox)自动联想功能的实现