Picture material for reference Ah Halle's Blog
The algorithm is used to solve the shortest path of one point to the remaining vertices
Let's start with a diagram and ask for the shortest path from 1 to 6.
It reminds me of the almost-hung branch of operations research.
Use a two-dimensional array first
There is also a one-dimensional array that stores the distance from 1 points to each point
The value of this one-dimensional array is called an estimate. Select a nearest point, point 2, at a point that can be reached directly at 1 points. Then the value of point 2 becomes the determined value.
Why Because the path is positive, it is not possible to shorten the distance from point 1 to 2 by other transit points.
After a bit of 2, look at what points 2 can reach. Point 3 and point 4. Let's discuss whether the transit point of point 2 can shorten the distance from point 1 to 3. The answer is yes. 1+9<12. Modifies the value of a one-dimensional array.
This is called relaxation .
In the same way compare points 1 to 4 distance and distance through point 2 relay.
The rest of the 3,4,5,6 points to try it out for themselves. Otherwise, operational research is easy to hang.
The final answer is
Sticking out the core algorithm
for (i=1;i<=n-1;i++) { //finds the vertex closest to number 1th vertex min=inf;//initial min is positive infinity for (j=1;j<=n;j++) { if ( Book[j]==0 && dis[j]<min) { min=dis[j];//gets the distance from the nearest point directly connected to the source point u=j; } } book[u]=1;//the point into the set of points that have been determined to go for (v=1;v<=n;v++)//This is like traversing the brother to point 2 distance { if (E[u][v]<inf) { if (Dis[v]>dis[u]+e[u][v]) dis[v]=dis[u]+e[u][v];}} }
Dijkstra algorithm---slack through edges