链接:

http://poj.org/problem?id=1273

Drainage Ditches
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 63763   Accepted: 24613

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

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
#define N 210
#define INF 0x3f3f3f3f int n, m, G[N][N], pre[N]; bool BFS(int Start, int End)
{
int p; queue<int>Q;
Q.push(Start); memset(pre, , sizeof(pre)); while(Q.size())
{
p = Q.front(), Q.pop(); if(p==End) return true; for(int i=; i<=End; i++)
{
if(!pre[i] && G[p][i])
{
pre[i] = p;
Q.push(i);
}
}
}
return false;
} int EM(int Start, int End)
{
int Max=;
while(BFS(Start, End)==true)
{
int Min=INF; for(int i=End; i!=Start; i=pre[i])
Min = min(Min, G[pre[i]][i]);
for(int i=End; i!=Start; i=pre[i])
{
G[pre[i]][i] -= Min;
G[i][pre[i]] += Min;
} Max += Min;
}
return Max;
} int main()
{
while(scanf("%d%d", &n, &m)!=EOF)
{
int i, u, v, p; memset(G, , sizeof(G));
for(i=; i<n; i++)
{
scanf("%d%d%d", &u, &v, &p);
G[u][v] += p;
} printf("%d\n", EM(, m));
}
return ;
}

(网络流 模板 Edmonds-Karp)Drainage Ditches --POJ --1273的更多相关文章

  1. (网络流 模板 Dinic) Drainage Ditches --POJ --1273

    链接: http://poj.org/problem?id=1273 代码: //Dinic #include<stdio.h> #include<string.h> #inc ...

  2. Drainage Ditches - poj 1273(网络流模板)

    题意:1是源点,m是汇点,求出来最大流量,没什么好说的就是练习最大流的模板题 ************************************************************* ...

  3. 网络流最经典的入门题 各种网络流算法都能AC。 poj 1273 Drainage Ditches

    Drainage Ditches 题目抽象:给你m条边u,v,c.   n个定点,源点1,汇点n.求最大流.  最好的入门题,各种算法都可以拿来练习 (1):  一般增广路算法  ford() #in ...

  4. POJ 1273 Drainage Ditches (网络流Dinic模板)

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

  5. POJ 1273:Drainage Ditches 网络流模板题

    Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 63339   Accepted: 2443 ...

  6. POJ 1273 Drainage Ditches(网络流dinic算法模板)

    POJ 1273给出M条边,N个点,求源点1到汇点N的最大流量. 本文主要就是附上dinic的模板,供以后参考. #include <iostream> #include <stdi ...

  7. POJ 1273 - Drainage Ditches - [最大流模板题] - [EK算法模板][Dinic算法模板 - 邻接表型]

    题目链接:http://poj.org/problem?id=1273 Time Limit: 1000MS Memory Limit: 10000K Description Every time i ...

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

    网络流模板题. ============================================================================================ ...

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

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

随机推荐

  1. SVM支持向量机推导,工具介绍及python实现

    支持向量机整理 参考: Alexandre KOWALCZYK大神的SVM Tutorial http://blog.csdn.net/alvine008/article/details/909711 ...

  2. 第一个gulp程序

    说起来惭愧,一直用公司内部的工具,没有用这些红得发紫的东西.今天东抄西拼终于搞出第一个gulp应用.gulp是做什么的,好处在哪儿我不废话了.直入主题吧. 先在D盘下建立一个xxxx目录,然后打开控制 ...

  3. 【转】Android Shape绘制虚线在手机端查看是实线的问题

    Android share绘制虚线在手机上显示实线问题 给控件添加Drawableleft等图片后,单独给图片设置动画效果,参考文章: http://blog.csdn.net/langzxz/art ...

  4. Eureka 源码编译 部署

    Netflix开源的Eureka 是使用Gradle 构建的,所以我们也使用Gradle来编译它   所需环境 Eclipse , Gradle , Tomcat ,git 这些插件如果己经安装可直接 ...

  5. 如何用INNO安装添加快捷启动方式到Win7的快速启动栏(超级任务栏)

    问题:如何用INNO安装添加快捷启动方式到Win7的快速启动栏(超级任务栏) 在XP下,添加方式是直接把快捷方式复制到%appdata%\Microsoft\Internet Explorer\Qui ...

  6. 如何学习mybatis

    最近几天学习了mybatis框架,我是mybatis视频学习的.看这篇文章,我建议首先要会熟练使用MVC架构,再学习这个框架. 在我们写传统的MVC模式写Bean,Dao,Servlet时,我们每次调 ...

  7. 37. Sudoku Solver (Array;Back-Track)

    Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by th ...

  8. Frog and Portal(思维好题)

    Frog and Portal https://hihocoder.com/problemset/problem/1873 时间限制:1000ms 单点时限:1000ms 内存限制:512MB 描述 ...

  9. error: In function ‘void* opencv_showimg(void*)’:

    今天这个问题折磨了我一下午,终于知道是为什么了,心酸历程.....赶紧来记录一下 错误: /home/wj/workspace/Loitor_VI_Sensor_SDK_V1./SDK/src/cam ...

  10. Codeforces 658A. Robbers' watch 模拟

    A. Robbers' watch time limit per test: 2 seconds memory limit per test: 256 megabytes input: standar ...