当前位置:网站首页>Classic Dijkstra and the longest way
Classic Dijkstra and the longest way
2022-07-28 15:13:00 【Pursue people far away】
Preface
There is a problem to find the shortest path And the question of the longest way , Because the foundation is not solid enough , Naively thought that the relaxation operation should be changed 、 Overload it Priority queue that will do . in fact , classic Dijkstra You can't find the longest way .
classic Dijkstra The longest path principle cannot be found
In the classic Dijkstra in , According to greedy thought , We use one point at a time that is the shortest from the source A To relax other points , And it ensures that this operation will only be carried out once at each point , That is, each point has and only once as a point A( Except for the farthest point , Because the last point is relaxed, the whole algorithm is over ).
as everyone knows , Dijastra's use condition is that there is no negative edge in the graph . This is because in a graph where there is no negative edge weight , The shortest path has substructures , The shortest sub path can ensure the shortest total path . According to this nature , There is also a conclusion , The point mentioned above to relax other points A, The distance from the source point is already the shortest ( This is also Dijsktra The premise that each point is only used to relax once ). However , There is no substructure in the following two cases :
- There is a negative edge weight , for example

- Seeking the longest way , for example

In a graph where there is no substructure , A point used to relax other points , It may not be the optimal solution . therefore , We can use algorithms that allow multiple relaxation (SPFA、 classic Dijsktra Change to allow one point to relax other points multiple times , In fact, it should be called SPFA 了 ) To find the longest way .
summary
- Finding the longest path in a positive weighted edge graph can be used SPFA
- classic Dijsktra You can run the longest way in the full negative weight edge graph 、 Running the shortest path in a full positive weighted edge graph
- Dijsktra+ The time complexity of heap optimization is O(ElogV)、SPFA(Bellman Ford)+ The time complexity of heap optimization is O(VE).
边栏推荐
- Rocky基础之修改网卡名为eth0
- 9、 C array explanation
- The modified network card name of rocky foundation is eth0
- 软件开发三大痛点!小程序容器如何解决?
- SQL error [1810] [22008]: ora-01810: format code occurs twice
- Slider restore and validation (legal database)
- celery 相关
- Hard disk partition method
- Machine learning related concepts
- Talk about low code / zero code tools
猜你喜欢

Repvgg paper explanation and model reproduction using pytoch

When MySQL uses left join to query tables, the query is slow because the connection conditions are not properly guided

DataTables warning: table id=campaignTable - Cannot reinitialise DataTable.解决
![What is the difference between UTF-8, utf-16 and UTF-32 character encoding? [graphic explanation]](/img/a9/336390db64d871fa1655800c1e0efc.png)
What is the difference between UTF-8, utf-16 and UTF-32 character encoding? [graphic explanation]

22、 TF coordinate transformation (II): static coordinate transformation

Untitled may

The automatic prompt of vs code code is missing - a tick to solve it

JS -- realize the rotation chart (complete function)

idea调试burpsuit插件

Idea2020.1.4 packages package collapse
随机推荐
9、 C array explanation
8、 C scope rules
20、 ROS distributed communication
网络安全应急响应具体操作流程
CCSP国际注册云安全专家在中国设置考场
18、 ROS topic name setting
What is the difference between UTF-8, utf-16 and UTF-32 character encoding? [graphic explanation]
3564. 日期类
Process finished with exit code-1073740791(0xC0000409)
4519. 正方形数组的数目
3715. Minimum number of exchanges
汇编学习
Bcompare key expired or bcompare license key revoked
3438. Number system conversion
redis常用命令总结(自备)
Image steganography method
软件开发三大痛点!小程序容器如何解决?
3511. Water pouring problem
Modify the default path of Jupiter notebook
Machine learning related concepts