HDU 1532Drainage Ditches
来源:互联网 发布:ioc java 编辑:程序博客网 时间:2024/06/13 06:08
Drainage Ditches
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 16605 Accepted Submission(s): 7889
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<iostream>#include<cstring>#include<cstdio>#include<cstdlib>#include<queue>#define INF 0x5fusing namespace std;struct Egde{int u,v,w,next;}e[500];int n,m,tot=1,head[500],ans,dep[500];void Add_Edge(int u,int v,int w){e[++tot].u=u;e[tot].v=v;e[tot].w=w;e[tot].next=head[u];head[u]=tot;}queue<int>q;bool BFS(int s,int t){while(!q.empty())q.pop();memset(dep,-1,sizeof dep );dep[s]=0;q.push(s);while(!q.empty()){int u=q.front();q.pop();for(int i=head[u];i;i=e[i].next){int v=e[i].v,w=e[i].w;if(dep[v]==-1&&w){dep[v]=dep[u]+1;q.push(v);}}}if(dep[t] != -1)return true;else return false;}int DFS(int u,int flow){int ret=0;if(u==n) return flow;for(int i=head[u];i;i=e[i].next){int v=e[i].v,w=e[i].w;if(dep[v]==dep[u]+1&&w){int x=DFS(v,min(w,flow-ret));ret+=x;e[i].w-=x;e[i^1].w+=x;}}return ret;}void Dinic(int s,int t){while(BFS(s,t))ans+=DFS(1,INF);}void Init(){memset(head,0,sizeof head );memset(e,0,sizeof e );tot=1;ans=0;}int main(){while(scanf("%d %d",&m,&n)!=EOF){Init();for(int u,v,w,i=1;i<=m;i++){scanf("%d %d %d",&u,&v,&w);Add_Edge(u,v,w);Add_Edge(v,u,0);}Dinic(1,n);printf("%d\n",ans);}return 0;}
0 0
- HDU 1532 Drainage Ditches
- hdu 1532 Drainage Ditches
- HDU 1532 Drainage Ditches
- hdu 1532 Drainage Ditches
- HDU 1532 Drainage Ditches
- hdu 1532 Drainage Ditches
- hdu 1532Drainage Ditches
- hdu 1532 Drainage Ditches
- hdu 1532 Drainage Ditches
- HDU 1532 Drainage Ditches
- HDU 1532 Drainage Ditches
- HDU 1532 Drainage Ditches
- hdu 1532 Drainage Ditches
- 【HDU】 1532 Drainage Ditches
- HDU 1532 - Drainage Ditches
- HDU 1532Drainage Ditches
- HDU 1532Drainage Ditches
- HDU-1532-Drainage Ditches
- 噩梦射手(SurvivalShooter)教程(十)
- TCP可靠传输的实现
- 最长回文子串的4种解法
- 基于注解和反射的Java ORM框架(3)-极速CRUD操作
- MVC框架
- HDU 1532Drainage Ditches
- spark2.0下 sparksql、dataframe、sqlsession 试用
- 浅谈ajax异步和同步加载的区别
- fseek函数、ftell函数和rewind函数
- 新起点
- 运算符的优先级
- JavaScript作用域链与闭包
- Ubuntu下指定Eclipse连接的jdk
- mysql安装在centos7报错ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)