(最大流)Drainage Ditches(P1273)
来源:互联网 发布:阿莱克丝塔萨 知乎 编辑:程序博客网 时间:2024/05/21 00:50
注意,可能有重边;
这个算法中要注意的就是还要记录其回流
#include<iostream>#include<cstdio>#include<algorithm>#include<queue>#include<vector>using namespace std;#define N 222int n,m;int path[N];queue<int> q;int map[N][N];int flow[N][N];int main(){freopen("in.txt","r",stdin);int i,j,k;while (cin>>m>>n){memset(map,0,sizeof(map));int ans=0;int a[N];while (m--){cin>>i>>j;cin>>k;map[i][j]+=k; //这里可以重边的。}while (!q.empty())q.pop();memset(flow,0,sizeof(flow));while (1){memset(a,0,sizeof(a));a[1]=100000000;q.push(1);while (!q.empty()){int u=q.front();q.pop();for (int v=1;v<=n;v++) if (!a[v] && map[u][v]>flow[u][v]){path[v]=u;q.push(v);a[v]=min(a[u],map[u][v]-flow[u][v]);}}if (!a[n])break;for (int u=n;u!=1;u=path[u]){flow[path[u]][u]+=a[n];flow[u][path[u]]-=a[n];}ans+=a[n];//cout<<ans<<' ';}cout<<ans<<endl;}return 0;}
Drainage Ditches
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 39866 Accepted: 14842
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
- (最大流)Drainage Ditches(P1273)
- Drainage Ditches 最大流
- HDOJ 1532 Drainage Ditches(最大流)
- Drainage Ditches (最大流问题)
- poj - 1273 - Drainage Ditches(最大流)
- poj1273--Drainage Ditches(最大流)
- HDU 1532 Drainage Ditches(最大流)
- HDU1532 Drainage Ditches(最大流)
- poj 1273 Drainage Ditches(最大流)
- HDU 1532 Drainage Ditches(最大流)
- poj1273 Drainage Ditches(最大流)
- hdu1532 Drainage Ditches(最大流)
- poj--1237--Drainage Ditches(最大流)
- POJ1273 Drainage Ditches(最大流)
- POJ-1273 Drainage Ditches(最大流)
- HDU1532 Drainage Ditches (最大流)
- HDU 1532 Drainage Ditches (最大流)
- POJ 1273 Drainage Ditches(最大流)
- android 解锁屏幕
- 设计模式六大原则之(三)----依赖倒置原则
- 把当前页面加进收藏夹
- Linux的shell与export命令
- jdbc以事物方式往mysql写数据
- (最大流)Drainage Ditches(P1273)
- Windows下遍历文件目录
- datagridview的checkbox列,当修改checkbox状态时实时获得其状态值
- html 文本输入框效果
- 实现TCP并发服务器之四(poll函数)
- linux下访问Windows中的共享目录
- 漫谈反问题及一些题外话
- asp.net验证控件备忘
- mysql数据库导出与导入