Find the shortest path with the least number of edges

前端 未结 5 495
渐次进展
渐次进展 2021-01-18 07:48

I need to modify Dijkstra\'s algorithm so that if there are several shortest paths I need to find the one with minimum number of edges on the path.

I\'ve been stuck

5条回答
  •  渐次进展
    2021-01-18 08:05

    Maintain minPathLen field for each vertex for dijktra.

    And in loop where you compare

       if(distance(s,u)+edge(u,v)

    Add another statement:-

     if((distance(s,u)+egde(u,v)==distance(s,v))&&(minPathLen(u)+1

提交回复
热议问题