Flow Problem

Time Limit: 5000/5000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 10184    Accepted Submission(s): 4798

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)
 
Output
For each test cases, you should output the maximum flow from source 1 to sink N.
 
Sample Input
2
3 2
1 2 1
2 3 1
3 3
1 2 1
2 3 1
1 3 1
 
Sample Output
Case 1: 1
Case 2: 2
 
Author
HyperHexagon
 
Source
 
Recommend
zhengfeng   |   We have carefully selected several similar problems for you:  1532 3572 3416 3081 3491 

  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<iostream>
  4. #include<algorithm>
  5. #include<queue>
  6. using namespace std;
  7. int dp[][],pre[];
  8. const int tmin=;
  9. int maxflow;
  10. void EK(int start,int end,int n){
  11. while(){
  12. queue<int>q;
  13. q.push();
  14. int minflow=tmin;
  15. memset(pre,,sizeof(pre));
  16. while(!q.empty()){
  17. int u=q.front();
  18. q.pop();
  19. for(int i=;i<=n;i++){
  20. if(dp[u][i]>&&!pre[i]){
  21. pre[i]=u;
  22. q.push(i);
  23. }
  24. }
  25. }
  26. if(pre[end]==)
  27. break;
  28. for(int i=end;i!=start;i=pre[i]){
  29. minflow=min(dp[pre[i]][i],minflow);
  30. }
  31. for(int i=end;i!=start;i=pre[i]){
  32. dp[pre[i]][i]-=minflow;
  33. dp[i][pre[i]]+=minflow;
  34. }
  35. maxflow+=minflow;
  36. }
  37. }
  38. int main(){
  39. int count=;
  40. int n,m;
  41. int t;
  42. scanf("%d",&t);
  43. while(t--){
  44. scanf("%d%d",&n,&m);
  45. memset(dp,,sizeof(dp));
  46. memset(pre,,sizeof(pre));
  47. count++;
  48. int u,v,w;
  49. for(int i=;i<=m;i++){
  50. scanf("%d%d%d",&u,&v,&w);
  51. dp[u][v]+=w;
  52. }
  53. maxflow=;
  54. EK(,n,n);
  55. printf("Case %d: %d\n",count,maxflow);
  56. }
  57. return ;
  58. }

HDU 3549 基础网络流EK算法 Flow Problem的更多相关文章

  1. 网络流Ek算法

    例题:  Flow Problem HDU - 3549 Edmonds_Karp算法其实是不断找增广路的过程. 但是在找的过程中是找"最近"的一天增广路, 而不是找最高效的一条增 ...

  2. 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) ...

  3. HDU1532 Drainage Ditches 网络流EK算法

    Drainage Ditches Problem Description Every time it rains on Farmer John's fields, a pond forms over ...

  4. 最大网络流 EK 算法

    网络流是什么类型的问题,看一道题目你就知道了 点击打开链接 . 默认具备图论的基本知识,网络流概念比较多,先看看书熟悉一下那些概念.比较好!一个寄出的网络最大流.EK算法写的. 这是一幅网络,求S   ...

  5. 网络流EK算法模板

    \(EK\)算法的思想就是每一次找一条增广路进行增广. 注意几个点: 存图时\(head\)数组要设为\(-1\). 存图的代码是这样的: inline void add(int u, int v, ...

  6. Drainage Ditches(网络流(EK算法))

    计算最大流,EK算法模板题. #include <stdio.h> #include <string.h> #include <queue> using names ...

  7. HDU 1532 Drainage Ditches EK算法 flod算法

    题意:输入m n, m是边数,n是点数. 接下来m行: 起点,终点,容量.求以 1 为源点, n为汇点的最大流. #include<stdio.h> #include<string. ...

  8. 网络流 EK算法模板。

    这篇博客讲得很好 #include<queue> #include<stdio.h> #include<string.h> using namespace std; ...

  9. hdu 3549最大流Ford-Fulkerson算法

    Ford-Fulkerson算法 戳戳http://www.cnblogs.com/luweiseu/archive/2012/07/14/2591573.html Ford-Fulkerson方法依 ...

随机推荐

  1. .net core自定义特性操作

    最近移植之前写的几个类,发现特性操作发生了一些改变. 直接看代码,建立表和字段特性类,添加一个用户表,设置好特性. using System; namespace TestDemo { /// < ...

  2. babel 不能统编译Iterator、Generator、Set、Maps、Proxy、Reflect、Symbol、Promise的问题

    Babel默认只转换新的JavaScript句法(syntax),而不转换新的API,比如Iterator.Generator.Set.Maps.Proxy.Reflect.Symbol.Promis ...

  3. 图解HTTP-1.web和网络基础

    目录 1. 3 项 WWW 构建技术 2. TCP/IP 是互联网相关的各类协议族的总称 协议(protocol) TCP/IP分层管理 TCP/IP通信传输流 封装(encapsulate) 3. ...

  4. Win10上Anaconda环境下python3.6安装和使用pyinstaller

    一.安装步骤 1. 电脑是win10,安装的Python3.6 2. 在Scripts文件夹下执行pip install pyinstaller, 安装成功后下载pyinstaller安装包,解压之后 ...

  5. python_字符串_常用处理

    1. 输出原序列的反向互补序列 in1 = open("brca1.fasta", "r") out1 = open("re_brca1.fasta& ...

  6. 前言 openwrt简介

    什么是openwrt?先看一下度娘怎么说. OpenWRT是一个高度模块化.高度自动化的嵌入式Linux系统,拥有强大的网络组件和扩展性,常常被用于工控设备.电话.小型机器人.智能家居.路由器以及VO ...

  7. B1008 数组元素循环右移问题 (20分)

    B1008 数组元素循环右移问题 (20分) 思路 1 2 3 4 5 6 5 6 1 2 3 4 6个数,循环右移2位. 也可以理解为 先翻转 6 5 4 3 2 1 然后再两部分,分别翻转 5 6 ...

  8. 2015 acm taipei L-Reward the Troop(uvalive 7465)(找规律)

    原题链接 就大概说的是一个将军要给部下发勋章,他的部下以和别人不一样的勋章为荣,但是他没这么多钱,所以问你最少要多少钱 要求是每个人的上司是他的上两级,他的下两级是他的部下,每个人的勋章不能和他的上司 ...

  9. 2037: [Sdoi2008]Sue的小球

    2037: [Sdoi2008]Sue的小球 链接 题解 论文 代码 #include<cstdio> #include<algorithm> #include<cstr ...

  10. com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 's.areaname' in 'field list'错误

    在使用mybatis框架做查询的时候,出现了如下错误: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown colum ...