The 1.Dijkstra algorithm (calculates the single-source shortest path Single-source shortest paths (SSSP) on a positive graph) from a single node to the shortest possible point of all nodes.
The algorithm is applicable to both the forward graph and the non-direction graph.
1). O (n^2) Implementation: adjacency matrix map Storage Implementation, INF representation infinity
void Dijkstra (int s, int e, int n)//shortest path from S to e point, N nodes, number: 0-->n-1. { memset (vis, 0, sizeof (VIS)); int I, J; for (i=0; i<n; i++) dis[i]= (i==0?0:inf); for (i=0; i<n; i++) { int mm=inf; int pos; for (j=0; j<n; j + +) { if (!vis[j] && dis[j]<m) m=dis[pos=j]; } Vis[pos]=1; for (j=0; j<n; j + +) { d[j]=min (dis[j], dis[pos]+map[pos][j]);} } printf ("%d\n", Dis[e]); Suppose the shortest path must exist}
Short-Circuit Algorithm summary (* "template")