hdu 1533 Drainage Ditches EK 网络流
来源:互联网 发布:阿里云免费 编辑:程序博客网 时间:2024/06/18 14:34
Drainage Ditches
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 12592 Accepted Submission(s): 6003
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.
Sample Input
5 41 2 401 4 202 4 202 3 303 4 10
Sample Output
50
Source
USACO 93
Recommend
lwg | We have carefully selected several similar problems for you: 1533 3338 1569 3572 3416
#include<cstdio>#include<string>#include<cstring>#include<iostream>#include<cmath>#include<algorithm>#include<climits>#include<queue>#include<vector>#include<map>#include<sstream>#include<set>#include<stack>#include<utility>#pragma comment(linker, "/STACK:102400000,102400000")#define PI 3.1415926535897932384626#define eps 1e-10#define sqr(x) ((x)*(x))#define FOR0(i,n) for(int i=0 ;i<(n) ;i++)#define FOR1(i,n) for(int i=1 ;i<=(n) ;i++)#define FORD(i,n) for(int i=(n) ;i>=0 ;i--)#define lson num<<1,le,mid#define rson num<<1|1,mid+1,ri#define MID int mid=(le+ri)>>1#define zero(x)((x>0? x:-x)<1e-15)#define mk make_pair#define _f first#define _s secondusing namespace std;const int INF =0x3f3f3f3f;const int maxn= 200+10 ;const int maxm= 200+10 ;//const int INF= ;typedef long long ll;const ll inf =1000000000000000;//1e15;//ifstream fin("input.txt");//ofstream fout("output.txt");//fin.close();//fout.close();//freopen("a.in","r",stdin);//freopen("a.out","w",stdout);//by yskysker123struct Edge{ int u,v,cap,flow; Edge(){} Edge(int s,int t,int c,int f):u(s),v(t),cap(c),flow(f){}} ;vector<Edge > E;vector<int > G[maxn];int pre[maxn],a[maxn];int n,m;inline void add_edge(int s,int t,int ca){ E.push_back( Edge( s,t,ca,0 ) ); E.push_back( Edge( t,s,0,0 ) ); int m=E.size(); G[s].push_back(m-2); G[t].push_back(m-1);}int Edmonskarp(){ int tot=0; while(1) { memset(pre,-1,sizeof pre); pre[1]=1; a[1]=INT_MAX; queue<int > q; q.push(1); while(!q.empty()) { int x=q.front();q.pop(); for(int i=0;i<G[x].size();i++) { Edge e=E[G[x][i]]; int y=e.v; if(pre[y]!=-1|| e.cap -e.flow <=0 ) continue; pre[y]=G[x][i]; a[y]=min(a[x],e.cap-e.flow); q.push(y); } if(pre[n]!=-1) break; } if(pre[n]==-1) break; tot+=a[n]; for(int p=n;p!=1;p=E[pre[p]].u ) { int e=pre[p]; E[e].flow+=a[n]; E[1^e].flow-=a[n]; } } return tot;}int main(){ int x,y,ca; while(~scanf("%d%d",&m,&n)) { E.clear(); FOR1(i,n) G[i].clear(); FOR1(i,m) { scanf("%d%d%d",&x,&y,&ca); add_edge(x,y,ca); } printf("%d\n",Edmonskarp() ); } return 0;}
0 0
- hdu 1533 Drainage Ditches EK 网络流
- hdu Drainage Ditches(网络流)
- HDU 1532 && POJ 1273 Drainage Ditches (网络流 EK算法)
- hdu 1532 Drainage Ditches 网络最大流模板 EK + Dinic两种算法AC
- HDU ACM 1532 Drainage Ditches->网络最大流模版题(EK算法实践)
- HDU 1532-Drainage Ditches(网络最大流,EK,Ford-Fulkerson,dinic3种算法套模板)
- 【网络流】最大流:Drainage Ditches【EK模板】
- poj 1273 Drainage Ditches (ek算法,网络流)
- POJ 1273 Drainage Ditches (网络流 EK && Dinic)
- POJ 1273~Drainage Ditches(网络最大流ek,dinic)
- hdu 1532 Drainage Ditches (最大流EK算法)
- hdu 1532 Drainage Ditches(最大流ek+dinic)
- hdu 1532 Drainage Ditches (最大流—EK算法)
- HDU 1532 Drainage Ditches——最大流EK算法
- hdu 1532 Drainage Ditches(EK算法)
- HDU 1532 Drainage Ditches (最大网络流)
- HDU 1532 Drainage Ditches (最大网络流)
- hdu 1532 Drainage Ditches(最大网络流)
- SpringMVC 基础教程 简单入门实例
- validate 表单验证 添加图片(image)
- 初学Linux 命令使用小技巧
- 鼠标坏了怎么用键盘操作鼠标
- 4个独立按键实现对数码管数字显示的加减清零等
- hdu 1533 Drainage Ditches EK 网络流
- 如何获取干净的的项目源码
- static java
- 从源hbase集群中复制出HBase数据库表到本地目录
- 线性回归问题
- 软工视频总结Part Four
- Caused by: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'name' at r
- 【Lua】如何利用lua进行热更新
- [参考资料] windows 2008 装 FreeSSHd