This summary is for the individual to prevent forgetting, do not reprint and commercial.
Topics
Given the undirected connectivity diagram shown in the figure, assuming that all edges in the graph have weights of 1, it is clear that there are multiple shortest paths from source point A to end point T, and the number of different shortest paths is obtained.
PS: The above figure A is the No. 0 node, B is the 1th node, other similar. Analysis
The shortest path problem with the same weights, the single source point Dijkstra algorithm degenerated into BFS breadth-first search: breadth-first search, i.e.:
From a:
Take one step to get to B or E
Take two steps to reach C or F
Walk three steps to reach D or G or K
....
Like this, every step of the way, expanding backwards.
Therefore, the definition:
The starting point is 0 and the end point is n
Step[i]: Indicates the length of the shortest path to the node I, such as: step[4] = 1,step[6] = 3.
Pathnum[i]: The number of shortest paths to the number I node.
First, initialize step[i] and pathnum[i] to 0,i = 0, 1, ..., N-1], and make pathnum[0]= 0, you have 1 ways to yourself.
Then consider "How to find the I+1 value when you have already calculated the first I value of step and Pathnum":
if step[i] = 0, then I have not yet reached J, i.e.: The current is the first time to reach J, so:
Step[j] = step[i]+1,pathnum[j] = Pathnum[i]
if step[j] = step[i]+1, then you have reached J from I, and this is a solution to the shortest path, so:
Pathnum[j] = pathnum[i]
Finally, when extended to node n, the algorithm terminates.