POJ 1273 Drainage Ditches
来源:互联网 发布:mac os x 10.9.5 编辑:程序博客网 时间:2024/06/11 23:02
Drainage Ditches
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 77293 Accepted: 30094
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.
Sample Input
5 41 2 401 4 202 4 202 3 303 4 10
Sample Output
50
Source
USACO 93
标准的模板题,我表示这个模板写得很好(✿◡‿◡)哈哈哈哈
n表示流量(即边数),m表示点的数量。
求从sink1到sourcem的最大流。
#include <cstdio>#include <iostream>#include <cstring>#include <algorithm>#include <cmath>#include <vector>#include <queue>using namespace std;#define INF 2100000000struct edge{int to,cap,rev;};vector<edge> G[1000];bool used[1000];void add_edge(int from,int to,int cap){G[from].push_back((edge){to,cap,G[to].size()});G[to].push_back((edge){from,0,G[from].size()-1});}int dfs(int v,int t,int f){if(v==t) return f;used[v]=true;for(int i=0;i<G[v].size();i++){edge &e=G[v][i];if(!used[e.to] && e.cap>0){int d=dfs(e.to,t,min(f,e.cap));if(d>0){e.cap-=d;G[e.to][e.rev].cap+=d;return d;}}}return 0;}int max_flow(int s,int t){int flow=0;for(;;){memset(used,0,sizeof(used));int f=dfs(s,t,INF);if(!f) return flow;flow+=f;}}int main(){int n,m;while(~scanf("%d%d",&n,&m)){memset(G,0,sizeof(G));for(int i=1;i<=n;i++){int u,v,c;scanf("%d%d%d",&u,&v,&c);add_edge(u,v,c);}printf("%d\n",max_flow(1,m));}return 0;}
阅读全文
1 0
- POJ 1273 Drainage Ditches
- POJ 1273 Drainage Ditches
- POJ 1273 Drainage Ditches
- poj 1273 Drainage Ditches
- poj 1273 Drainage Ditches
- POJ 1273 Drainage Ditches
- POJ 1273 Drainage Ditches
- POJ-1273-Drainage Ditches
- poj 1273 Drainage Ditches
- POJ 1273 Drainage Ditches
- poj 1273 Drainage Ditches
- POJ 1273 Drainage Ditches
- POJ-1273-Drainage Ditches
- poj 1273 Drainage Ditches
- POJ 1273 Drainage Ditches
- poj 1273 Drainage Ditches
- POJ 1273 Drainage Ditches
- POJ 1273 Drainage Ditches
- EU4-33: Sloving an employee problem
- 浅谈树链剖分
- Java中Class类与RTTI
- 手机的唯一识别符
- 第17课
- POJ 1273 Drainage Ditches
- Angular 2基础(一) 环境搭建
- matlab 怎么在直角坐标系中添加最值得数值
- 过滤器和拦截器的区别
- 信息安全第三篇(网络传输的加密与解密)
- C++中的四种运算符转化及不同点:
- 【win】mysql解压版的安装
- 自定义Linearlayout,实现dividerPaddingLeft和dividerPaddingRight
- 15. 3Sum