Flow Problem

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

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:  3572 3416 3081 3491 1533 
 
 

一个证明需要反向更新的例子:

这个图从1到6明显最的流量为3+3=6,但如果不用反向更新,由于用BFS首先找到一条路径1-2-3-6,然后1-2,2-3,3-6这几条边被更新成了0,就再也找不到增广路径到6了,而1-5-3的剩余的5个流量就无路可走了,用反向更新会再在3-2这里加一条流量为3的边,这时候1-5-3的5流量就可以通过这条边到2再到4再到6了,这就是反向更新的需要。

参考:http://blog.csdn.net/huanglianzheng/article/details/5754057

网络最大流入门模板题:

ford fulkerson 标号法:

 //750MS    4216K    1444 B    C++
#include<iostream>
#include<queue>
#define INF 0x7ffffff
#define N 1005
using namespace std;
int g[N][N],flow[N]; //记录流量fij, 和每次的调整值flow[e]
int father[N],vis[N]; //记录父节点 和 标记已遍历节点
int maxflow,n,m;
inline int Min(int a,int b)
{
return a<b?a:b;
}
void ford_fulkerson(int s,int e)
{
queue<int>Q;
maxflow=;
while(){ //调整到无增广链为止
memset(flow,,sizeof(flow));
memset(vis,,sizeof(vis));
flow[s]=INF;
Q.push(s);
while(!Q.empty()){
int u=Q.front();
Q.pop();
for(int v=;v<=n;v++){
if(!vis[v] && g[u][v]>){
vis[v]=;
father[v]=u;
Q.push(v);
flow[v]=Min(flow[u],g[u][v]);
}
}
if(flow[e]>){
while(!Q.empty()) Q.pop();
break;
}
}
if(flow[e]==) break;
for(int i=e;i!=s;i=father[i]){
g[father[i]][i]-=flow[e];
g[i][father[i]]+=flow[e];
}
maxflow+=flow[e];
}
}
int main(void)
{
int t,k=;
int a,b,c;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
memset(g,,sizeof(g));
for(int i=;i<m;i++){
scanf("%d%d%d",&a,&b,&c);
g[a][b]+=c;
}
ford_fulkerson(,n);
printf("Case %d: %d\n",k++,maxflow);
}
return ;
}

hdu 3549 Flow Problem (网络最大流)的更多相关文章

  1. HDU 3549 Flow Problem(最大流)

    HDU 3549 Flow Problem(最大流) Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/ ...

  2. hdu 3549 Flow Problem【最大流增广路入门模板题】

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=3549 Flow Problem Time Limit: 5000/5000 MS (Java/Others ...

  3. HDU 3549 Flow Problem (最大流ISAP)

    Flow Problem Time Limit: 5000/5000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Tota ...

  4. hdu 3549 Flow Problem(最大流模板题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3549 Problem Description Network flow is a well-known ...

  5. HDU 3549 Flow Problem(最大流模板)

    http://acm.hdu.edu.cn/showproblem.php?pid=3549 刚接触网络流,感觉有点难啊,只好先拿几道基础的模板题来练练手. 最大流的模板题. #include< ...

  6. 题解报告:hdu 3549 Flow Problem(最大流入门)

    Problem Description Network flow is a well-known difficult problem for ACMers. Given a graph, your t ...

  7. hdu 3549 Flow Problem 【最大流】

    其实还是不是很懂dinic----- 抄了一个模板--- http://www.cnblogs.com/naturepengchen/articles/4403408.html 先放在这里--- #i ...

  8. 网络流 HDU 3549 Flow Problem

    网络流 HDU 3549 Flow Problem 题目:pid=3549">http://acm.hdu.edu.cn/showproblem.php?pid=3549 用增广路算法 ...

  9. hdu 3549 Flow Problem

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=3549 Flow Problem Description Network flow is a well- ...

随机推荐

  1. agc 027 B - Garbage Collector

    B - Garbage Collector https://agc027.contest.atcoder.jp/tasks/agc027_b 题意: x坐标轴上n个垃圾,有一个机器人在从原点,要清扫垃 ...

  2. java中的比较:instanceof、equals(hashcode)、==

    import javassist.expr.Instanceof; class Person{ String s; Person(String s){ this.s=s; } } class Man ...

  3. http tcp udp

    HTTP连接 1.HTTP协议即超文本传送协议(Hypertext Transfer Protocol ),是Web联网的基础,也是手机联网常用的协议之一,HTTP协议是建立在TCP协议之上的一种应用 ...

  4. OSG-基础知识-程序框架

    本文转至http://www.cnblogs.com/shapherd/archive/2010/08/10/osg.html 作者写的比较好,再次收藏,希望更多的人可以看到这个文章 互联网是是一个相 ...

  5. 用Python实现一个端口扫描,只需简单几步就好

    一.常见端口扫描的原理 0.秘密扫描 秘密扫描是一种不被审计工具所检测的扫描技术. 它通常用于在通过普通的防火墙或路由器的筛选(filtering)时隐藏自己. 秘密扫描能躲避IDS.防火墙.包过滤器 ...

  6. [JSON].remove( keyPath )

    语法:[JSON].remove( keyPath ) 返回:无 说明:移除指定路径的键 示例: Set jsonObj = toJson("{div:{'#text-1': 'is tex ...

  7. String和StringBuffer以及StringBuilder的区别

    今天在读<java编程思想>的时间,在看到String和StringBuffer以及StringBuffer这三个类的时间,做一个随笔小结,为自己的面试做好准备! 一:String,Str ...

  8. 如何处理 jQuery $(window).resize() 中的方法被多次执行的小问题

    引言: 估计很多同志们在编写浏览器resize()的方法时,都会遇到这样的情况: 当拖动浏览器的边角时,页面中的一些效果随浏览器大小的改变而触发,这一过程开始到结束,resize() 中的方法被执行了 ...

  9. HDU 2492 Ping pong(数学+树状数组)(2008 Asia Regional Beijing)

    Description N(3<=N<=20000) ping pong players live along a west-east street(consider the street ...

  10. No Route to Host from master/192.168.2.131 to master:9000 failed on socket t

    host里边添加的ip地址与当前的ip地址(ifconfig可以查看)不一致,修改当前ip地址就可以了.