POJ 1273 Drainage Ditches
来源:互联网 发布:java自学需要多久 编辑:程序博客网 时间:2024/04/27 05:49
题目链接 : POJ1273
Drainage Ditches
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 46915 Accepted: 17658
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
#include<cstdio>#include<cstring>#include<cmath>#include<cstdlib>#include<algorithm>#include<string>#include<vector>#include<map>using namespace std;int n,m,s,t;vector<int> gra[205];int cap[205][205],flow[205][205];int que[205],p[205],a[205];int max_flow(){int ans=0;memset(flow,0,sizeof(flow));while(1){int tail=0,front=1,x,y;que[0]=s;memset(a,0,sizeof(a));a[s]=0x3fffffff;while(front>tail){x=que[tail++];for(int i=0;i<gra[x].size();i++){y=gra[x][i];if(flow[x][y]<cap[x][y] && !a[y]){que[front++]=y;p[y]=x;a[y]=min(a[x],cap[x][y]-flow[x][y]);}}if(a[t]) break;}if(!a[t]) return ans;x=t;while(x!=s) {flow[x][p[x]]-=a[t];flow[p[x]][x]+=a[t];x=p[x];}ans+=a[t];}return 0;}int main(){//freopen("1.txt","r",stdin);while(scanf("%d%d",&m,&n)==2){int x,y,w;memset(cap,0,sizeof(cap));for(int i=1;i<=n;i++)gra[i].clear();for(int i=0;i<m;i++){scanf("%d%d%d",&x,&y,&w);cap[x][y]+=w;gra[x].push_back(y);gra[y].push_back(x);}s=1;t=n;printf("%d\n",max_flow());} return 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
- linux eof
- Useful Bash examples
- webpy的url动态匹配
- js实现跑马灯效果
- Linux环境下GDB的使用
- POJ 1273 Drainage Ditches
- /var/log目录下的20个Linux日志文件功能详解
- 拔河比赛-动态规划
- hdu2554
- hdoj 2037 (贪心)(结构体排序)
- ThinkPHP 这样入门
- Snowlinux 4 发布,基于 Debian 的 Linux 发行版
- 第四届“蓝桥杯”全国软件专业人才设计与创业大赛选拔赛 C/C++本科B组 主讲解题思想
- C语言运算符优先级表