flow

浅谈网络流

六月ゝ 毕业季﹏ 提交于 2019-11-26 20:36:40
网络流是什么? 网络流(network-flows)是一种类比水流的解决问题方法,与线性规划密切相关。网络流的理论和应用在不断发展,出现了具有增益的流、多终端流、多商品流以及网络流的分解与合成等新课题。网络流的应用已遍及通讯、运输、电力、工程规划、任务分派、设备更新以及计算机辅助设计等众多领域。 图论中的一种理论与方法,研究网络上的一类最优化问题 。1955年 ,T.E.哈里斯在研究铁路最大通量时首先提出在一个给定的网络上寻求两点间最大运输量的问题。1956年,L.R. 福特和 D.R. 富尔克森等人给出了解决这类问题的算法,从而建立了网络流理论。所谓网络或容量网络指的是一个连通的赋权有向图 D= (V、E、C) , 其中V 是该图的顶点集,E是有向边(即弧)集,C是弧上的容量。此外顶点集中包括一个起点和一个终点。网络上的流就是由起点流向终点的可行流,这是定义在网络上的非负函数,它一方面受到容量的限制,另一方面除去起点和终点以外,在所有中途点要求保持流入量和流出量是平衡的。如果把下图看作一个公路网,顶点v1…v6表示6座城镇,每条边上的权数表示两城镇间的公路长度。现在要问 :若从起点v1将物资运送到终点v6去 ,应选择那条路线才能使总运输距离最短?这样一类问题称为最短路问题 。 如果把上图看作一个输油管道网 , v1 表示发送点,v6表示接收点,其他点表示中转站

HDU-4289-Control(最大流最小割,拆点)

依然范特西╮ 提交于 2019-11-26 19:36:37
链接: https://vjudge.net/problem/HDU-4289 题意: You, the head of Department of Security, recently received a top-secret information that a group of terrorists is planning to transport some WMD 1 from one city (the source) to another one (the destination). You know their date, source and destination, and they are using the highway network.   The highway network consists of bidirectional highways, connecting two distinct city. A vehicle can only enter/exit the highway network at cities only.   You may locate some SA (special agents) in some selected cities, so that when the terrorists enter a city

图论--网络流--最大流 HDU 3572 Task Schedule(限流建图,超级源汇)

这一生的挚爱 提交于 2019-11-26 18:26:08
Problem Description Our geometry princess XMM has stoped her study in computational geometry to concentrate on her newly opened factory. Her factory has introduced M new machines in order to process the coming N tasks. For the i-th task, the factory has to start processing it at or after day Si, process it for Pi days, and finish the task before or at day Ei. A machine can only work on one task at a time, and each task can be processed by at most one machine at a time. However, a task can be interrupted and processed on different machines on different days. Now she wonders whether he has a

图论--网络流--费用流POJ 2195 Going Home

左心房为你撑大大i 提交于 2019-11-26 18:19:03
Description On a grid map there are n little men and n houses. In each unit time, every little man can move one unit step, either horizontally, or vertically, to an adjacent point. For each little man, you need to pay a $1 travel fee for every step he moves, until he enters a house. The task is complicated with the restriction that each house can accommodate only one little man. Your task is to compute the minimum amount of money you need to pay in order to send these n little men into those n different houses. The input is a map of the scenario, a '.' means an empty space, an 'H' represents a

网络流-最小费用最大流

为君一笑 提交于 2019-11-26 18:17:21
定义 有时,网络中每条边除了容量还有费用。最小费用最大流(MincostMaxflow,简称MCMF)就是在最大流的基础上,费用最小。 实现 和EK类似,最小费用最大流的求法也是暴力寻找增广路,但是不是用Bfs进行增广,而是用Bellman-Ford或者Spfa进行增广。寻找增广路时,先要满足可以增广,然后检查费用是否更优秀,两者都满足,才修正。这样增广下来,不难发现肯定满足费用最小。 这个算法的效率是玄学……但是实际运用中应该可能大概够了吧。 模板 实在没找到模板题,用 POJ2135 当模板题好了。 因为每条道路只能通过一次,所以我们可以认为每条道路的容量为1,费用为这条道路的长度(由于这道题是双向边,所以必须正反都建边)。但是要走回来怎么办?因为不能重复走,所以走回来就等价于走两次(已双向建边),我们可以增加两个虚拟节点0和n+1:0向1构造一条容量为2,费用为0的边,n向n+1构造一条容量为2,费用为0的边。然后直接刷最小费用最大流即可。 #include<cstdio> #include<cstring> #include<algorithm> using namespace std ; const int maxn= 1000 ,maxm= 40000 ; int n,m,E,lnk[maxn+ 5 ],son[maxm+ 5 ],nxt[maxm+ 5 ]; int

图论--网络流--费用流--POJ 2156 Minimum Cost

ⅰ亾dé卋堺 提交于 2019-11-26 18:16:39
Description Dearboy, a goods victualer, now comes to a big problem, and he needs your help. In his sale area there are N shopkeepers (marked from 1 to N) which stocks goods from him.Dearboy has M supply places (marked from 1 to M), each provides K different kinds of goods (marked from 1 to K). Once shopkeepers order goods, Dearboy should arrange which supply place provide how much amount of goods to shopkeepers to cut down the total cost of transport. It's known that the cost to transport one unit goods for different kinds from different supply places to different shopkeepers may be different.

图论--网络流最大流问题

北城以北 提交于 2019-11-26 18:15:52
问题表述: 给定一幅图(n个结点,m条边),每一条边有一个容量,现在需要将一些物品从结点s(称为源点)运送到结点t(称为汇点),可以从其他结点中转,求最大的运送量。 在介绍最大流问题的解决方法之前,先介绍几个概念. 网络 :网络是一个有向带权图,包含一个源点和一个汇点,没有反向平行边。 网络流 :网络流即网上的流,是定义在网络边集E上的一个非负函数flow={flow(u,v)}, flow(u,v)是边上的流量。 可行流 :满足以下两个性质的网络流flow称为可行流。 容量约束 :每条边的实际流量不能超过改变的最大流量。 流量守恒 :除了源点s和汇点t之外,所有内部节点流入量等于流出量。 源点s :源点主要是流出,但也有可能流入。 源点的净输出值=流出量之和-流入量之和。 汇点t :汇点主要是流入,但也有可能流出。 汇点的净输入值=流入量之和-流出量之和。 对于一个网络可行流flow,净输出等于净输入,这仍然是流量守恒。 网络最大流 :在满足容量约束和流量守恒的前提下,在流网络中找到一个净输出最大的网络流。 反向弧: 若从u到v的边的 容量 为c ,这条边上有流量 f 流过(称为正向弧),则相当于v到u有一条容量为0的边,其流量为- f ,这条边就是反向弧。反向弧的作用主要是用于寻找增广路。 反向弧的意义: 反向弧的作用是起到有更优 决策 的时候会使当前选择的弧会自动放弃

经典网络流题目模板(P3376 + P2756 + P3381 : 最大流 + 二分图匹配 + 最小费用最大流)

落爺英雄遲暮 提交于 2019-11-26 18:12:59
题目来源 P3376 【模板】网络最大流 P2756 飞行员配对方案问题 P3381 【模板】最小费用最大流 最大流 最大流问题是网络流的经典类型之一,用处广泛,个人认为网络流问题最具特点的操作就是建反向边,这样相当于给了反悔的机会,不断地求增广路的,最终得到最大流 #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<queue> #include<string> #include<fstream> #include<vector> #include<stack> #include <map> #include <iomanip> #define bug cout << "**********" << endl #define show(x,y) cout<<"["<<x<<","<<y<<"] " //#define LOCAL = 1; using namespace std; typedef long long ll; const int inf = 0x3f3f3f3f; const ll mod = 1e6 + 3; const int Max = 1e5 + 10; struct Edge { int to, next, flow; /

图论--最小费用最大流(MCMF)

断了今生、忘了曾经 提交于 2019-11-26 18:12:31
以下为提高+难度。 关于这个算法我不多做阐述,因为我说的肯定没有lrj大神说得好,大家可以看他的书–《算法竞赛入门经典》,那里有详细描述。 到了这种难度,极其建议大家去抄抄代码,过一遍手,比什么都强。 我也是这一遍抄完了,才感觉这两天的网络流明白了。 下来就是代码。 code: //洛谷 P3381 【模板】最小费用最大流 #include<bits/stdc++.h> #define ll long long using namespace std ; const int maxn= 10001 ,inf= 0x3f3f3f3f ; struct edge{ int from,to,cap,flow,cost; edge( int u, int v, int c, int f, int d):from(u),to(v),cap(c),flow(f),cost(d){} }; struct MCMF{ int n,s,t; ll cost,flow; vector <edge> edges; vector < int > G[maxn]; int a[maxn],p[maxn],d[maxn],in[maxn]; void init( int n, int s, int t){ this ->n=n; this ->s=s; this ->t=t; flow= 0 ; cost=

HDU-4292-Food(最大流,Dinic)

余生颓废 提交于 2019-11-26 17:53:16
链接: https://vjudge.net/problem/HDU-4292 题意:   You, a part-time dining service worker in your college’s dining hall, are now confused with a new problem: serve as many people as possible.   The issue comes up as people in your college are more and more difficult to serve with meal: They eat only some certain kinds of food and drink, and with requirement unsatisfied, go away directly.   You have prepared F (1 <= F <= 200) kinds of food and D (1 <= D <= 200) kinds of drink. Each kind of food or drink has certain amount, that is, how many people could this food or drink serve. Besides, You know