minimal-circuit Dijkstra Array Implementation
/* Dijkstra Array Implementation O (N ^ 2) <br/> Dijkstra --- Array Implementation (on this basis, you can directly change it to the queue Implementation of STL) <br/> G [] [] --- adjacent array, the initial distance from I to j <br/> Dist [] --- the closest distance from beg to other points <br/> path [] --- beg is the root expanded tree, record the parent node */<br/> # define INF 0x7ffffff <br/> # define n 1008 <br/> int path [N], vis [N]; <br/> int G [N] [N], DIST [N] [N]; <br/> void Dijkstra (int n, int beg) {<br/> int I, j, min; <br/> memset (VIS, 0, sizeof (VIS); <br/> vis [beg] = 1; <br/> for (I = 0; I <n; I ++) {<br/> Dist [I] = G [beg] [I]; <br/> path [I] = beg; <br/>}< br/> Dist [beg] = 0; <br/> path [beg] =-1; // tree root flag <br/> int pre = beg; <br/> for (I = 1; I <n; I ++) {<br/> min = inf; <br/> for (j = 0; j <n; j ++) <br/> If (vis [J] = 0 & Dist [pre] + G [pre] [J] <Dist [J]) {<br/> Dist [J] = DIST [pre] + G [pre] [J]; <br/> path [J] = pre; <br/>}< br/> for (j = 0; j <n; j ++) <br/> If (vis [J] = 0 & Dist [J] <min) {<br/> min = DIST [J]; <br/> pre = J; <br/>}< br/> vis [pre] = 1; <br/>}< br/>}