HDU 3549 基础网络流EK算法 Flow Problem
Flow Problem
Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 10184 Accepted Submission(s): 4798
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.
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)
3 2
1 2 1
2 3 1
3 3
1 2 1
2 3 1
1 3 1
Case 2: 2
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int dp[][],pre[];
const int tmin=;
int maxflow;
void EK(int start,int end,int n){
while(){
queue<int>q;
q.push();
int minflow=tmin;
memset(pre,,sizeof(pre));
while(!q.empty()){
int u=q.front();
q.pop();
for(int i=;i<=n;i++){
if(dp[u][i]>&&!pre[i]){
pre[i]=u;
q.push(i);
}
}
}
if(pre[end]==)
break;
for(int i=end;i!=start;i=pre[i]){
minflow=min(dp[pre[i]][i],minflow);
}
for(int i=end;i!=start;i=pre[i]){
dp[pre[i]][i]-=minflow;
dp[i][pre[i]]+=minflow;
}
maxflow+=minflow;
}
}
int main(){
int count=;
int n,m;
int t;
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&m);
memset(dp,,sizeof(dp));
memset(pre,,sizeof(pre));
count++;
int u,v,w;
for(int i=;i<=m;i++){
scanf("%d%d%d",&u,&v,&w);
dp[u][v]+=w;
}
maxflow=;
EK(,n,n);
printf("Case %d: %d\n",count,maxflow);
}
return ;
}
HDU 3549 基础网络流EK算法 Flow Problem的更多相关文章
- 网络流Ek算法
例题: Flow Problem HDU - 3549 Edmonds_Karp算法其实是不断找增广路的过程. 但是在找的过程中是找"最近"的一天增广路, 而不是找最高效的一条增 ...
- POJ 1459 网络流 EK算法
题意: 2 1 1 2 (0,1)20 (1,0)10 (0)15 (1)20 2 1 1 2 表示 共有2个节点,生产能量的点1个,消耗能量的点1个, 传递能量的通道2条:(0,1)20 (1,0) ...
- HDU1532 Drainage Ditches 网络流EK算法
Drainage Ditches Problem Description Every time it rains on Farmer John's fields, a pond forms over ...
- 最大网络流 EK 算法
网络流是什么类型的问题,看一道题目你就知道了 点击打开链接 . 默认具备图论的基本知识,网络流概念比较多,先看看书熟悉一下那些概念.比较好!一个寄出的网络最大流.EK算法写的. 这是一幅网络,求S ...
- 网络流EK算法模板
\(EK\)算法的思想就是每一次找一条增广路进行增广. 注意几个点: 存图时\(head\)数组要设为\(-1\). 存图的代码是这样的: inline void add(int u, int v, ...
- Drainage Ditches(网络流(EK算法))
计算最大流,EK算法模板题. #include <stdio.h> #include <string.h> #include <queue> using names ...
- HDU 1532 Drainage Ditches EK算法 flod算法
题意:输入m n, m是边数,n是点数. 接下来m行: 起点,终点,容量.求以 1 为源点, n为汇点的最大流. #include<stdio.h> #include<string. ...
- 网络流 EK算法模板。
这篇博客讲得很好 #include<queue> #include<stdio.h> #include<string.h> using namespace std; ...
- hdu 3549最大流Ford-Fulkerson算法
Ford-Fulkerson算法 戳戳http://www.cnblogs.com/luweiseu/archive/2012/07/14/2591573.html Ford-Fulkerson方法依 ...
随机推荐
- miller——rabin
突然发现自己在线性筛素数中有这个,忘了好久: #include<iostream> #include<cstdio> using namespace std; long lon ...
- left join后面加上where条件浅析
select a.*,b.* from table1 a left join table2 b on b.X=a.X where XXX 如上:一旦使用了left join,没有where条件时,左表 ...
- 一个老鸟发的公司内部整理的 Android 学习路线图 Markdown 版本
jixiaohua发了一篇一个老鸟也发了一份他给公司内部小伙伴整理的路线图.另一份 Android 开发学习路线图.可惜不是MarkDown格式的,所以jixiaohua直接上传的截图,在jixiao ...
- EBS R12中FND凭证打印警告:OPP响应超时
接近年关,最近年结忙的飞起,此为背景,今天运维那边反应日记账凭证打印报错,看了下后台请求发现请求有警告. 查看日志发现报了“并发:OPP响应超时”的警告,这个地方响应超时可能是配置文件中“并发:OPP ...
- 内置函数SQLCODE和SQLERRM的使用
由于ORACLE的错信息最大长度是512字节,为了得到完整的错误提示信息,我们可用 SQLERRM 和 SUBSTR 函数一起得到错误提示信息,方便进行错误,特别是如果WHEN OTHERS异常处理器 ...
- Spring 中IOC(控制反转)&& 通过SET方式为属性注入值 && Spring表达式
### 1. Spring IoC IoC:Inversion of control:控制反转:在传统开发模式下,对象的创建过程和管理过程都是由开发者通过Java程序来实现的,操作权在开发者的Java ...
- idea中使用逆向工程----三部曲
逆向工程小伙伴可能都知道,可以根据公司大佬的数据库简单创建实体类和dao接口以及mapper的映射文件,逆向工程可能在数据库字段比较少的时候体现不会方便,但是当参与到数据库字段比较多的时候,我们不可能 ...
- Salt-ssh 自动安装salt-minion
作用:为了不手动去安装一台一台去salt-minion,并进重复的配置 一.环境 系统环境: #cat /etc/redhat-release CentOS Linux release 7.4.170 ...
- Delphi7卸载indy9,安装indy10步骤
1. 找到C:\Program Files\Borland\Delphi7\Borland Delphi7.msi——双击——点Next——选择Modify,点Next——找到Program File ...
- 图像的模糊-opencv
调用两个API,一个是均值模糊,一个是高斯模糊.如下所示: #include<opencv2/opencv.hpp> #include<iostream> using name ...