hdu 1532 Drainage Ditches(最大流)
来源:互联网 发布:单片机好学吗 编辑:程序博客网 时间:2024/05/20 20:01
题目:
链接:点击打开链接
题意:
求最大流速。
思路:
Edmond_karp就行。
代码:
#include <iostream>#include <cstdio>#include <cstring>#include <queue>using namespace std;#define INF 100000000const int N = 220;int cap[N][N],flow[N][N];int a[N];int n,m;int s,e,c;void edmonds_karp(int s,int t){ queue<int> q; memset(flow,0,sizeof(flow)); int f = 0; int p[N]; for(;;) { memset(a,0,sizeof(a)); a[s] = INF; q.push(s); while(!q.empty()) { int u = q.front(); q.pop(); for(int v=1; v<=n; v++) { if(!a[v] && cap[u][v] > flow[u][v]) { p[v] = u; q.push(v); a[v] = a[u] < cap[u][v] - flow[u][v] ? a[u] : cap[u][v] - flow[u][v]; } } } if(a[t] == 0) break; for(int u=t; u!=s; u=p[u]) { flow[p[u]][u] += a[t]; flow[u][p[u]] += a[t]; } f += a[t]; } printf("%d\n",f);}int main(){ //freopen("input.txt","r",stdin); while(scanf("%d%d",&n,&m) != EOF) { memset(cap,0,sizeof(cap)); for(int i=0; i<n; i++) { scanf("%d%d%d",&s,&e,&c); cap[s][e] += c; } edmonds_karp(1,m); } return 0;}--------------------------------------------------------------------------------
收获:
------>增广路算法,Edmond_karp模板:
queue<int> q; memset(flow,0,sizeof(flow)); int f = 0; int p[N]; for(;;) { memset(a,0,sizeof(a)); a[s] = INF; q.push(s); while(!q.empty()) { int u = q.front(); q.pop(); for(int v=1; v<=n; v++) { if(!a[v] && cap[u][v] > flow[u][v]) { p[v] = u; q.push(v); a[v] = a[u] < cap[u][v] - flow[u][v] ? a[u] : cap[u][v] - flow[u][v]; } } } if(a[t] == 0) break; for(int u=t; u!=s; u=p[u]) { flow[p[u]][u] += a[t]; flow[u][p[u]] += a[t]; } f += a[t]; }
------------------------------------------------------------------
战斗,从不退缩;奋斗,永不停歇~~~~~~~~~~~~~
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 1532] Drainage Ditches(最大流dinic)
- hdu 1532 Drainage Ditches(最大流)
- hdu 1532 Drainage Ditches 最大流 水题
- hdu 1532 最大网络流 Drainage Ditches
- HDU 1532 Drainage Ditches 最大流
- HDU 1532 Drainage Ditches(最大流)
- Drainage Ditches - HDU 1532 最大流
- HDU 1532--Drainage Ditches【最大流】
- hdu 1532 Drainage Ditches(最大流)
- HDU 1532 Drainage Ditches(最大流)
- hdu 1532 Drainage Ditches【最大流】
- HDU 1532 Drainage Ditches (最大流模板)
- setAnimatjionStyle实现popupwindow的动画效果
- servlet里经常会用到的一些GET方法
- js动态时钟
- “ant debug install” 出错: sdk.dir is missing. Make sure....
- 业内人说:后媒体时代,我们需要怎样的创业者?
- hdu 1532 Drainage Ditches(最大流)
- 《设计师要懂心理学》摘要
- sqlite3 C简单编程实例
- form表单转换为json对象
- 关于注释
- sqlite使用参考网址
- 嗯,让我们彻底搞懂C/C++函数指针吧(一)
- JRTPLIB使用实例
- C++课程设计 教职工管理系统