The Bellman-Ford algorithm
This algorithm deals with the general case, where G is a directed, weight graph, and it can contains negative edge weigths, cycles and even negative-weight cycles. It runs in O(VE) time, which means O(V^3) when the graph is dense.
This algorithm detects cycles by checking "v.d > u.d + w(u, v)", this is viable because if there are no negative-weight cycles, and there is an edge which satisfies "v.d > u.d + w(u, v)", v.d would be replaced by u.d + w(u, v) which is exactly what Relax(u,v, w) does. Thus at the time of checking all edges would satisfiy "v.d <= u.d + w(u, v)". Consider the Relax(u,v,w) procedure as "If there are still space for optimizing, then optimize it."
If there are negative-weight cycles, we can consider this as there are infinite optimizing space which can never be fulled exploited. So there will always be some edge whose shortest distance can still be optimized after the "enough" Relax process.
The Bellman-Ford algorithm的更多相关文章
- ACM/ICPC 之 最短路径-Bellman Ford范例(POJ1556-POJ2240)
两道Bellman Ford解最短路的范例,Bellman Ford只是一种最短路的方法,两道都可以用dijkstra, SPFA做. Bellman Ford解法是将每条边遍历一次,遍历一次所有边可 ...
- poj1860 bellman—ford队列优化 Currency Exchange
Currency Exchange Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 22123 Accepted: 799 ...
- uva 558 - Wormholes(Bellman Ford判断负环)
题目链接:558 - Wormholes 题目大意:给出n和m,表示有n个点,然后给出m条边,然后判断给出的有向图中是否存在负环. 解题思路:利用Bellman Ford算法,若进行第n次松弛时,还能 ...
- Bellman—Ford算法思想
---恢复内容开始--- Bellman—Ford算法能在更普遍的情况下(存在负权边)解决单源点最短路径问题.对于给定的带权(有向或无向)图G=(V,E),其源点为s,加权函数w是边集E的映射.对图G ...
- Bellman - Ford 算法解决最短路径问题
Bellman - Ford 算法: 一:基本算法 对于单源最短路径问题,上一篇文章中介绍了 Dijkstra 算法,但是由于 Dijkstra 算法局限于解决非负权的最短路径问题,对于带负权的图就力 ...
- Dijkstra算法与Bellman - Ford算法示例(源自网上大牛的博客)【图论】
题意:题目大意:有N个点,给出从a点到b点的距离,当然a和b是互相可以抵达的,问从1到n的最短距离 poj2387 Description Bessie is out in the field and ...
- poj1860 兑换货币(bellman ford判断正环)
传送门:点击打开链接 题目大意:一个城市有n种货币,m个货币交换点,你有v的钱,每个交换点只能交换两种货币,(A换B或者B换A),每一次交换都有独特的汇率和手续费,问你存不存在一种换法使原来的钱更多. ...
- ACM/ICPC 之 Bellman Ford练习题(ZOJ1791(POJ1613))
这道题稍复杂一些,需要掌握字符串输入的处理+限制了可以行走的时间. ZOJ1791(POJ1613)-Cave Raider //限制行走时间的最短路 //POJ1613-ZOJ1791 //Time ...
- poj3259 bellman——ford Wormholes解绝负权问题
Wormholes Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 35103 Accepted: 12805 Descr ...
- POJ 2240 Arbitrage (Bellman Ford判正环)
Arbitrage Time Limit: 1000MS Memory Limit: 65536K Total Submissions:27167 Accepted: 11440 Descri ...
随机推荐
- PPTP、L2TP、IPSec和SSLVPN的区别
VPN (虚拟专用网)发展至今已经不在是一个单纯的经过加密的访问隧道了,它已经融合了访问控制.传输管理.加密.路由选择.可用性管理等多种功能,并在全球的信息安全体系中发挥着重要的作用.也在网络上,有关 ...
- jhipster
Client side: yeoman,grunt,bower,angularjs Server side: maven,spring,spring mvc rest,spring data jpa
- wxPython ImportError DLL load failed: %1 不是有效的 Win32 应用程序 解决办法
原因:python是32位的,装了64位的Wxpython时会报错,具体错误是安装库文件与python的动态库的位数未一致. 特别留意32位/64位指的不是 系统的位数,而是Python的位数. 64 ...
- html代码实现自动滚动,鼠标滑过时停止滚动
<marquee style="width: 1200px;height:200px;margin:0px auto" onmouseout="this.start ...
- SQL Developer 4.1.3
http://www.oracle.com/technetwork/developer-tools/sql-developer/downloads/index.html SQL DeveloperDo ...
- 基于JAVA WEB的医药管理系统
学习上可以模仿,但是不可以抄袭! 附加百度链接:http://wenku.baidu.com/link?url=_r44vGCi8pcm6o44YCvkcHGoT_XhB8jURnweao2YVo1j ...
- 3d max地形建造
这里来记录一下max里面建造一个地形. 1.创建一个平面,调节平面的属性,包括长宽,和分段 2.然后建造一个道路 然后选择样条线工具,调节线条的轮廓. 3.使用合并工具,将线条和地面进行合并成为一个物 ...
- ASP.NET MVC5总结(四)登陆中常用技术解析之验证码
在应用软件中,登陆系统我们往往会用到验证码技术,下面将介绍在MVC中用到的验证码技术. 1.前端代码段及前端效果图如下 <div class="row"> <in ...
- HDU 4707 Pet(BFS)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4707 题目大意:在一个无环的,从0开始发散状的地图里,找出各个距离0大于d的点的个数 Sample I ...
- UVA 11584 Paritioning by Palindromes(动态规划 回文)
题目大意:输入一个由小写字母组成的字符串,你的任务是把它划分成尽量少的回文串.比如racecar本身就是回文串:fastcar只能分成7个单字母的回文串:aaadbccb最少可分成3个回文串:aaa. ...