hdu 1532 Drainage Ditches
来源:互联网 发布:哪本书讲lms rls算法 编辑:程序博客网 时间:2024/05/22 03:27
点击打开题目链接
裸的最大流问题,用的是SAP算法。
#include<iostream>#include<cstdio>#include<cstring>#define clr(a,b) memset(a,b,sizeof(a))#define M 0xfffffusing namespace std;const int I=300;int map[I][I],pre[I],dis[I],gap[I];int SAP(int s,int t){ clr(pre,-1); clr(dis,0); clr(gap,0); gap[0]=t; int u=s,ans(0); while(dis[s]<t) { int v; for(v=1;v<=t;v++) { if(map[u][v]>0 && dis[u]==dis[v]+1) break; } if(v<=t) { pre[v]=u; u=v; if(v==t) { int minflow=M; for(int i=v;i!=s;i=pre[i]) { if(minflow>map[pre[i]][i]) minflow=map[pre[i]][i]; } ans+=minflow; for(int i=v;i!=s;i=pre[i]) { map[pre[i]][i]-=minflow; map[i][pre[i]]+=minflow; } u=s; } } else { int mindis=t; for(int i=1;i<=t;i++) { if(map[u][i]>0 && mindis>dis[i]+1) mindis=dis[i]+1; } --gap[dis[u]]; if(gap[dis[u]]==0) return ans; dis[u]=mindis; gap[mindis]++; if(u!=s) u=pre[u]; } } return ans;}int main(){ int n,m; while(~scanf("%d%d",&n,&m)) { clr(map,0); for(int i=0;i<n;i++) { int a,b,c; scanf("%d%d%d",&a,&b,&c); map[a][b]+=c; } int ans=SAP(1,m); printf("%d\n",ans); } return 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
- gSoap开发Web Service 既soapcpp2.exe生成服务端和客户端的代码具体方法
- 访问父类中的被覆盖成员、初始化父类构造函数
- A. Adding Digits
- linux下QT程序编译时的错误:QMAKESPEC has not been set, so configuration cannot be deduced.
- Java打印设置属性
- hdu 1532 Drainage Ditches
- oracle个人学习总结
- python中的pickle如何使用
- 质量属性需求有哪些?
- eclipse常用快捷键
- ubuntu中liveCD、desktop与alternate版本的区别
- jdom学习:读取xml文件
- 编译Linux内核的方法
- CMMI-DEV相关知识点一