HBC236065[SHOI2013]发微博,线段树,数据结构Shortest Path Fast Algorithm题解

不可一世的小女人 算法基础篇 39 0
想要成为编程高手?那就来试试全网最全C++题库,让您在练习中快速成长。
Recently, BaoBao has learned the Shortest Path Fast Algorithm to solve the shortest path problem efficiently. He realizes that the algorithm looks so similar to the Dijkstra's algorithm after replacing the FIFO queue with priority queue, and shows you the below pseudo code. By picking the best vertex from QQQ we mean picking the vertex with the smallest priority value . You, the future computer scientist, find the BaoBao-modified SPFA algorithm works so slow in some carefully construted graph. However, BaoBao is sure that his algorithm works well, unless you show him a simple undirected graph that makes the variable cntin the SPFA function no less than a certain kkk at some time. For convenience the source vertex of the SPFA function is specified to be vertex 111. Just teach him a lesson!

Recently, BaoBao has learned the Shortest Path Fast Algorithm (SPFA, or more formally, Bellman-Ford-Moore Algorithm) to solve the shortest path problem efficiently. He realizes that the algorithm looks so similar to the Dijkstra's algorithm after replacing the FIFO queue with priority queue, and shows you the below pseudo code. By picking the best vertex from QQQ we mean picking the vertex with the smallest priority value (in case that multiple vertices have the smallest priority value, pick the vertex with the largest index among them). You, the future computer scientist, find the BaoBao-modified SPFA algorithm works so slow in some carefully construted graph. However, BaoBao is sure that his algorithm works well, unless you show him a simple undirected graph that makes the variable cnt in the SPFA function no less than a certain kkk at some time. For convenience the source vertex of the SPFA function is specified to be vertex 111. Just teach him a lesson!

HBC236065[SHOI2013]发微博,线段树,数据结构Shortest Path Fast Algorithm题解
-第1张图片-东莞河马信息技术
(图片来源网络,侵删)
不断挑战自我,才能突破极限!全网最全C++题库,让您在编程道路上越走越远。

标签: HBC236065[SHOI2013]发微博 线段树 数据结构Shortest Path Fast Algorithm题解