POJ 1273 Drainage Ditches 网络流 ISAP
来源:互联网 发布:畅捷通软件介绍 编辑:程序博客网 时间:2024/06/05 14:36
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
传送门
题目大意是,,很多水管,然后巴拉巴拉。。。
总之求最大流裸题!($
不得不说很不喜欢poj,hdu这种,,,虽然有些题目只能在它们上面做。
首先poj不能用bits/stdc++.h这个头文件。。。每题CE似乎必然。
然后poj的题目都是多组测试数据。。。靠,有什么意义吗??
事实上的话,,我这题真的脑餐好多地方。。。
改了很久!后来发现,,反向边的容量应该是0,,
还有就是更新最大流的时候手贱了,+=写成==。。笔记本的问题。。
网络流上,ISAP的时间复杂度最多O(V^2*E)。。实际上远不到这个把。。
由于这题范围小,边不多,其实是可以用EK水过去的。。
对于没有练过ISAP的我来说,,还是写一发把。。
自己看的模板是这个blog:
http://blog.csdn.net/u013368721/article/details/30490255
哦提一句,学会了一个新姿势。。
!x,x=0返回1.
~x,x>=0返回1.
//#include<bits/stdc++.h>#include<cstdio>#include<cstring> using namespace std;int read(){ int x=0,f=1;char ch=getchar(); while (ch<'0' || ch>'9'){if (ch=='-') f=-1;ch=getchar();} while (ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}const int N=205;int n,m,Ecnt;int pre[N],cur[N],num[N],Q[N],d[N];struct Edge{int next,to,C;}E[N<<1]; int head[N];void add(int x,int y,int z){E[Ecnt].next=head[x];E[Ecnt].to=y;E[Ecnt].C=z;head[x]=Ecnt++;}void BFS(int source,int sink){memset(num,0,sizeof(num));memset(d,255,sizeof(d));d[sink]=0;num[0]=1;int Head=0,tail=0;Q[tail++]=sink;while (Head!=tail){int u=Q[Head++];for (int i=head[u];~i;i=E[i].next){int j=E[i].to;if (~d[j]) continue;d[j]=d[u]+1;num[d[j]]++;Q[tail++]=j;}}}int Isap(int source,int sink){memcpy(cur,head,sizeof(cur));BFS(source,sink);int flow=0,u;u=pre[source]=source;while (d[sink]<n+1){if (u==sink){int f=999999,neck;for (int i=source;i!=sink;i=E[cur[i]].to)if (f>E[cur[i]].C){f=E[cur[i]].C;neck=i;}for (int i=source;i!=sink;i=E[cur[i]].to)E[cur[i]].C-=f,E[cur[i]^1].C+=f;flow+=f;u=neck; }int j;for (j=cur[u];~j;j=E[j].next)if (d[E[j].to]+1==d[u] && E[j].C)break;if (~j){cur[u]=j;pre[E[j].to]=u;u=E[j].to;}else{num[d[u]]--;if (!num[d[u]]) break;int mind=n+1;for (int i=head[u];~i;i=E[i].next)if (E[i].C && mind>d[E[i].to]){cur[u]=i;mind=d[E[i].to];}d[u]=mind+1;num[d[u]]++;u=pre[u];}}return flow;}void solve(){memset(head,255,sizeof(head));int x,y,z;Ecnt=0;for (int i=0;i<m;i++){x=read(),y=read(),z=read();add(x,y,z);add(y,x,0); //opposite side}printf("%d\n",Isap(1,n));}int main(){while (~scanf("%d%d",&m,&n))solve();return 0;}
阅读全文
0 0
- POJ 1273 Drainage Ditches 网络流 ISAP
- POJ-1273 Drainage Ditches (ISAP)
- POJ--1273--Drainage Ditches【Dinic模板】【isap模板】网络最大流
- Poj 1273 Drainage Ditches (最大流EK+ISAP)
- POj 1273 Drainage Ditches (最大流 Dinic + ISAP 模板)
- 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 网络流算法 .
- 在Ubuntu上下载、编译和安装Android最新源代码
- 反射详解
- Android Bitmap处理
- miniui表格分页(mybatis)
- C++fstream,ifstream和outstream读取文件最后一行注意
- POJ 1273 Drainage Ditches 网络流 ISAP
- C++ 带默认形参值的函数
- CPU中的八个通用寄存器
- Android系统级开发进程清理功能的一些记录和发现
- Ubuntu 16.04 安装Opencv3.1.0 (选装opencv_contrib模块)
- java-09
- 如何mount guest vm的parition到dom0
- bzoj1901Zju2112 Dynamic Rankings 带修改可持久化线段树
- STM32F103系列读写LCD1604显示屏