Code:
#include <stdio.h> #include <string.h> #include <string> #include <vector> #include < Algorithm> #define INF 2100000000using namespace std;int n;struct node{int dd; int W;} t;vector<node>q[500001];unsigned int Dis[500001];bool vis[500001];void Dijkstra (int s, int e) {int i, J; Memset (Vis, false, sizeof (VIS)); for (i=0; i<=n; i++) {dis[i] = INF; } int len=q[s].size (); for (i=0; i<len; i++) {if (Q[S][I].W < dis[q[s][i].dd]) DIS[Q[S][I].DD]=Q[S][I].W;//DIS number from start point Group Update} vis[s]=true; for (int k=0; k<n-1; k++) {int pos, mm=inf; for (I=1; i<=n; i++) {if (!vis[i] && dis[i]<mm) {//The current node has not been accessed and has a lower weight value Mm=dis[i]; Pos=i; }} vis[pos]=true; Update the DIS array len=q[pos].size () again; for (j=0; j<len; J + +) {if (!vis[q[pos][j].dd] && dis[q[pos][j].dd]>q[pos][j]. W+dis[pos]) dis[q[pos][j].dd] = Q[POS][J].W + Dis[pos]; }} printf ("%d\n", Dis[e]);} int main () {int m; int i; int U,v, W; int S, E; while (scanf ("%d%d", &n, &m)!=eof) {for (i=0; i<=n; i++) q[i].clear (); for (i=0; i<m; i++) {scanf ("%d%d%d", &u, &v, &w); T.dd=v; T.w=w; Q[u].push_back (t); T.dd=u; T.w=w; Q[v].push_back (t); } scanf ("%d%d", &s, &e); Dijkstra (S, e); } return 0;}
Did a run big data of the shortest-circuiting hanging, vector-based two-dimensional analog adjacency table implementation of the Dijkstra algorithm (* "template")