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题解