Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 51   Accepted Submission(s) : 33
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
USACO 93
KE 算法
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<queue>
#include<deque>
#include<iomanip>
#include<vector>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<fstream>
#include<memory>
#include<list>
#include<string>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MAXN 1100
#define L 31
#define INF 1000000009
#define eps 0.00000001
/*
最大流问题
*/
int g[MAXN][MAXN], path[MAXN], flow[MAXN], start, End, n, m;
int bfs()
{
queue<int> q;
q.push(start);
memset(path, -, sizeof(path));
path[start] = ;
flow[start] = INF;
while (!q.empty())
{
int tmp = q.front();
q.pop();
if (tmp == End) break;
for (int i = ; i <= n; i++)
{
if (i != start&&g[tmp][i] && path[i] == -)
{
flow[i] = min(g[tmp][i], flow[tmp]);
path[i] = tmp;
q.push(i);
}
}
}
if (path[End] == -) return -;
return flow[End];
}
int EK()
{
int max_flow = , now, step;
while ((step = bfs())!= -)
{
max_flow += step;
now = End;
while (now != start)
{
int pre = path[now];
g[pre][now] -= step;
g[now][pre] += step;
now = pre;
}
}
return max_flow;
}
int main()
{
while (scanf("%d%d", &m, &n) != EOF)
{
memset(g, , sizeof(g));
int f, t, d;
for (int i = ; i < m; i++)
{
scanf("%d%d%d", &f, &t, &d);
g[f][t] += d;
}
start = , End = n;
printf("%d\n", EK());
}
}

网络流入门 Drainage Ditches的更多相关文章

  1. USACO93网络流入门Drainage Ditches 排水渠(DCOJ 5130)

    题目描述 (传送门:http://poj.org/problem?id=1273翻译 by sxy(AFO的蒟蒻)) 每次约翰的农场下雨,Bessie的水池里的四叶草就会被弄破.这就意味着,这些四叶草 ...

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

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

  3. nyoj_323:Drainage Ditches(网络流入门)

    题目链接 网络流入门@_@,此处本人用的刘汝佳的Dinic模板 #include<bits/stdc++.h> using namespace std; const int INF = 0 ...

  4. HDU-1532 Drainage Ditches,人生第一道网络流!

    Drainage Ditches 自己拉的专题里面没有这题,网上找博客学习网络流的时候看到闯亮学长的博客然后看到这个网络流入门题!随手一敲WA了几发看讨论区才发现坑点! 本题采用的是Edmonds-K ...

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

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

  6. 【网络流】POJ1273 Drainage Ditches

    Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 78671   Accepted: 3068 ...

  7. POJ1273 Drainage Ditches (网络流)

                                                             Drainage Ditches Time Limit: 1000MS   Memor ...

  8. HDU 1532 Drainage Ditches (网络流)

    A - Drainage Ditches Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64 ...

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

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

随机推荐

  1. 必会!Linux文件的管理

    1.1 创建一个目录 /data [root@liuhao ~]# mkdir /data 1.2 查看目录是否创建成功 <可以找到data即为创建成功> [root@liuhao ~]# ...

  2. oracleXE简易版---使用基础

    1.开启服务 2.更改端口号 a)   EX修改HTTP服务端口,避免和TOMCAT端口冲突 Oracel默认会启动HTTP服务,占有端口8080,但一般8080时TOMCAT的配置端口 可以修改TO ...

  3. 8.22 NOIP 模拟题

      8.22 NOIP 模拟题 编译命令 g++ -o * *.cpp gcc -o * *.c fpc *.pas 编译器版本 g++/gcc fpc 评测环境 位 Linux, .3GHZ CPU ...

  4. Unity项目 - 吃豆人Pacman

    项目展示 Github项目地址:Pacman 涉及知识 切片制作 Animations 状态机设置,any state切换,重写状态机 按键读取进行整数距离的刚体移动 用射线检测碰撞性 渲染顺序问题 ...

  5. 分享一些对IT人员非常好用的资源

    前言 分享一下本人工作至今整理的一些好用的资源,这些资源主要是一些工作和生活中用到的文档.软件和网站. 文档主要是面试相关的文档和技术文档,其中面试文档主要是Java这块的,技术文档就有很多,除了Ja ...

  6. 关于static函数在类中的定义和使用

    刷题的时候遇到了这样一个问题:平时经常使用 sort()函数, 对结构体进行排序, 但是在类中使用时会出现 这样的错误提示:“Solution::cmp”: 函数调用缺少参数列表:请使用“&S ...

  7. mysql数据库存储的引擎和数据类型

    一.查看支持的存储引擎 SHOW ENGINES \G; 或者 SHOW VARIABLES LIKE 'have%'; 二.安装版mysql的默认引擎是InnoDB,免安装版默认引擎是MyISAM ...

  8. Java——Spring注解

    Spring常用注解使用注解来构造IoC容器用注解来向Spring容器注册Bean.需要在applicationContext.xml中注册<context:component-scan bas ...

  9. build.gradle(Mdule.app)依赖库相关

    dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) //noinspection GradleCompati ...

  10. html中设置浏览器解码方式

    通过添加一行标签: <meta http-equiv="Content-Type" content="text/html; charset=utf-8"& ...