hdu 3549 Flow Problem(最大流模版题 Edmonds-Karp算法)
来源:互联网 发布:梅林传奇 滚娘 知乎 编辑:程序博客网 时间:2024/05/19 04:53
Flow Problem
Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 5984 Accepted Submission(s): 2786
Problem Description
Network flow is a well-known difficult problem for ACMers. Given a graph, your task is to find out the maximum flow for the weighted directed graph.
Input
The first line of input contains an integer T, denoting the number of test cases.
For each test case, the first line contains two integers N and M, denoting the number of vertexes and edges in the graph. (2 <= N <= 15, 0 <= M <= 1000)
Next M lines, each line contains three integers X, Y and C, there is an edge from X to Y and the capacity of it is C. (1 <= X, Y <= N, 1 <= C <= 1000)
For each test case, the first line contains two integers N and M, denoting the number of vertexes and edges in the graph. (2 <= N <= 15, 0 <= M <= 1000)
Next M lines, each line contains three integers X, Y and C, there is an edge from X to Y and the capacity of it is C. (1 <= X, Y <= N, 1 <= C <= 1000)
Output
For each test cases, you should output the maximum flow from source 1 to sink N.
Sample Input
23 21 2 12 3 13 31 2 12 3 11 3 1
Sample Output
Case 1: 1Case 2: 2最大流模版题,Edmonds-Karp算法while(存在增广路){找到任意一条增广路;更新残余网络;}AC代码:#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <queue>#include <stack>#include <vector>#include <cmath>#include <cstdlib>#define L(rt) (rt<<1)#define R(rt) (rt<<1|1)#define ll long long#define eps 1e-6using namespace std;const int INF=1000000000;int c[20][20],f[20][20];int n,m;int bfs(){ queue<int>Q; int a[20],pre[20]; int ans=0; memset(f,0,sizeof(f)); while(1) { memset(a,0,sizeof(a)); a[1]=INF; Q.push(1); while(!Q.empty()) { int u=Q.front(); Q.pop(); for(int v=1; v<=n; v++) if(!a[v]&&c[u][v]>f[u][v]) { pre[v]=u; Q.push(v); a[v]=min(a[u],c[u][v]-f[u][v]); } } if(!a[n]) break; for(int u=n;u!=1;u=pre[u]) { f[pre[u]][u]+=a[n]; f[u][pre[u]]-=a[n]; } ans+=a[n]; } return ans;}int main(){ int t,ca=0; int x,y,z; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); memset(c,0,sizeof(c)); while(m--) { scanf("%d%d%d",&x,&y,&z); c[x][y]+=z; } printf("Case %d: %d\n",++ca,bfs()); } return 0;}
- hdu 3549 Flow Problem(最大流模版题 Edmonds-Karp算法)
- 最大流Edmonds-Karp算法模版
- hdu 3549 Flow Problem(最大流,Edmond Karp)
- hdu 1532 Drainage Ditches(Edmonds-Karp最大流算法)
- 最大流-Edmonds-Karp算法
- hdoj 3549 Flow Problem---最大流---Edmond Karp算法
- 网络流(最大流---Edmonds-Karp算法)
- 网络流最大流 Edmonds-Karp算法
- 网络流 最大流 Edmonds-Karp算法
- Edmonds-Karp算法,网络流最大流
- 求最大流Ford-Fulkerson方法(Edmonds-Karp算法)
- 最大流 - Edmonds-Karp 增广路算法
- 最大流算法模板 Edmonds—Karp
- 最大流问题 Edmonds-Karp算法
- [最大流]增广路算法Edmonds-Karp
- 最大流的Edmonds-Karp算法
- edmonds-karp算法求最大流
- HDU 3549 Flow Problem(网络流水题【Edmond-Karp算法】)
- Linux下SVN服务器搭建(CentOS+Subversion)
- 优化页面HTML式样
- SpringMVC获取request对象和response对象
- 低级鼠标钩子WH_MOUSE_LL
- 判断字符串是否包含另一字符串的全排列
- hdu 3549 Flow Problem(最大流模版题 Edmonds-Karp算法)
- Zigbee关联表AssociatedDevList的操作
- spring整合struts2的应用
- 开发人员视角的网站性能
- linux shell 字体颜色
- ItemsControl 之template
- HTML jsp 登陆界面
- django自带的server能让外网主机访问
- 渗透测试实验(《网络攻防技术与实践》与《Metasploit渗透测试指南》读书实验)