Drainage Ditches

时间限制:1000 ms  |  内存限制:65535 KB
难度:4
描述
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.

输入
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.
输出
For each case, output a single integer, the maximum rate at which water may emptied from the pond.
样例输入
5 4
1 2 40
1 4 20
2 4 20
2 3 30
3 4 10
样例输出
50
来源
USACO 93
上传者
张洁烽

FF算法,不看模板,一遍AC(练手)同poj

代码:

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const int INF=0x3f3f3f3f;
const int maxn=1e3+5;
int capacity[maxn][maxn],flow[maxn][maxn];
int v;
int networkflow(int source, int sink) {
int totalflow=0;
memset(flow,0,sizeof(flow));
while(true) {
queue<int> q;
vector<int> parent(maxn,-1);
parent[source]=source;
q.push(source);
while(!q.empty()) {
int here=q.front();q.pop();
for(int there=0;there<v;there++) {
if(capacity[here][there]-flow[here][there]>0&&parent[there]==-1) {
parent[there]=here;
q.push(there);
}
}
}
if(parent[sink]==-1) break;
int amount=INF;
for(int p=sink;p!=source;p=parent[p]) {
amount=min(amount,capacity[parent[p]][p]-flow[parent[p]][p]);
}
for(int p=sink;p!=source;p=parent[p]) {
flow[parent[p]][p]+=amount;
flow[p][parent[p]]-=amount;
}
totalflow+=amount;
}
return totalflow;
}
int main() {
int n,m;
while(~scanf("%d%d",&m,&n)) {
v=n;
memset(capacity,0,sizeof(capacity));
for(int i=0;i<m;++i) {
int x,y,c;
scanf("%d%d%d",&x,&y,&c);
capacity[x-1][y-1]+=c;
}
printf("%d\n",networkflow(0,n-1));
}
return 0;
}

NYOJ 323 Drainage Ditches 网络流 FF 练手的更多相关文章

  1. POJ 1273 Drainage Ditches 网络流 FF

    Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 74480   Accepted: 2895 ...

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

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

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

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

  4. HDU1532 Drainage Ditches 网络流EK算法

    Drainage Ditches Problem Description Every time it rains on Farmer John's fields, a pond forms over ...

  5. USACO 4.2 Drainage Ditches(网络流模板题)

    Drainage DitchesHal Burch Every time it rains on Farmer John's fields, a pond forms over Bessie's fa ...

  6. Drainage Ditches~网络流模板

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

  7. poj 1273 Drainage Ditches 网络流最大流基础

    Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 59176   Accepted: 2272 ...

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

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

  9. [POJ1273][USACO4.2]Drainage Ditches (网络流最大流)

    题意 网络流最大流模板 思路 EK也不会超时 所以说是一个数据比较水的模板题 但是POJ有点坑,多组数据,而且题目没给 哭得我AC率直掉 代码 用的朴素Dinic #include<cstdio ...

随机推荐

  1. Tomcat 服务器及使用Eclipse绑定Tomcat并发布应用

    一.简介 Tomcat是Apache 软件基金会(Apache Software Foundation)的Jakarta 项目中的一个核心项目,由Apache.Sun 和其他一些公司及个人共同开发而成 ...

  2. Linux上安装二进制文件MySQL详解

    前言:昨天晚上搞了很久,终于搞清楚mysql的安装配置了,我真是太low了.当我在云服务器上登进Mysql时,真是高兴哈哈,咱一步一步来,彻底搞懂Mysql的安装配置. 我的安装环境: 阿里云服务器 ...

  3. JDBC连接池-C池3P0连接

    JDBC连接池-C3P0连接 c3p0连接池的学习英语好的看英文原版      c3p0 - JDBC3 Connection and Statement Pooling 使用c3p0连接池  三种方 ...

  4. win10 安装Node.js 报错:2503

    解决方法: 使用管理员打开CMD

  5. Python-数据类型-转摘

    1.数字 2 是一个整数的例子.长整数 不过是大一些的整数.3.23和52.3E-4是浮点数的例子.E标记表示10的幂.在这里,52.3E-4表示52.3 * 10-4.(-5+4j)和(2.3-4. ...

  6. 八皇后问题 dfs/递归

    #include <bits/stdc++.h> using namespace std; const int maxn = 55; int ans=0; int vis_Q[maxn]; ...

  7. 实现基于Keepalived高可用集群网站架构的多种方法

    实现基于Keepalived高可用集群网站架构 随着业务的发展,网站的访问量越来越大,网站访问量已经从原来的1000QPS,变为3000QPS,目前业务已经通过集群LVS架构可做到随时拓展,后端节点已 ...

  8. c#params应用

    params 是C#开发语言中关键字, params主要的用处是在给函数传参数的时候用,就是当函数的参数不固定的时候. 在方法声明中的 params 关键字之后不允许任何其他参数,并且在方法声明中只允 ...

  9. Android 异步消息处理机制前篇(一):深入理解ThreadLocal

    版权声明:本文出自汪磊的博客,转载请务必注明出处. ThreadLocal简介 ThreadLocal是一个线程内部的数据存储类,通过它可以在指定的线程中存储数据,数据存储以后,只有在指定线程中可以获 ...

  10. JS初学运用

    JS一点认知: JavaScrip组成:ECMAScript  核心 BOM ---Browser Object Model 游览器对象模型 DOM  文档模型  document JavaScrip ...