. 1 #include <cstdio> 2 #include <CString> . 3 #include <algorithm> . 4 #include <the iostream> . 5 #include <Vector> . 6 #include <Stack> . 7 the using namespace STD; . 8 const int MAXN = 505 ; . 9 const int INF = 0x3f3f3f3f ; 10 int n-, m, S, D; . 11 int SP [MAXN]; // number of relief 12 is int DJ [MAXN]; // distance shortest distance starting point 13 is intVIS [MAXN]; // the inclusion of a set of 14 int Road [MAXN]; // shortest path number of 15 int path [MAXN]; // prefix node 16 int Total [MAXN]; // total number of relief . 17 struct City 18 is { . 19 int E; 20 is int len; 21 is }; 22 is Vector <City> VE [MAXN]; 23 is // initialization 24 void the init () 25 { 26 is Memset (VIS, 0 , the sizeof (VIS)); 27 memset (total,0,sizeof(total)); 28 memset (road,0,sizeof(road)); 29 memset (path,-1,sizeof(path)); 30 for (int i=0;i<n;i++) 31 dj[i]=INF; 32 dj[s]=0; 33 total[s]=sp[s]; 34 road[s]=1; 35 } 36 void djst () 37 { 38 is the while ( . 1 ) 39 { 40 int Maxx = INF; 41 is int U = - . 1 ; 42 is for ( int I = 0 ; I <n-; I ++ ) 43 is IF (DJ [I] <Maxx &&! VIS [I]) 44 is { 45 Maxx = DJ [I]; 46 is u = I; 47 } 48 IF (u == - . 1 ) // if u still or equal to -1 DESCRIPTION all the points have been minimized, the loop end 49 BREAK ; 50 VIS [u] = . 1 ; // otherwise an intermediary to a point u as to extend to the periphery 51 is for ( int I = 0 ; I <VE [u] .size (); I ++ ) 52 is { 53 is int V = VE [u] [I] .E; // to point u through point u to find edges point v, v point to diffuse 54 is IF (VIS [v]!) // If v has not visited point 55 { 56 is IF (DJ [v]> DJ [U] + VE [U] [I] .LEN) // if the direct v to v farther than the point reached by u, is updated at 57 is { 58 DJ [v] DJ = [U ] + VE [U] [I] .LEN; 59 path [v] = u; // record what path, the precursor is v u 60 Road [v] = Road [u]; // to v shortest path and the shortest path number to u as strip 61 is Total [ v] = Total [u] + SP [v]; // to rescue the number v is the number of the number to u + v relief 62 is 63 is } 64 the else IF (DJ [v] == DJ [u] + VE [ u] [I] .LEN) // if directly to V and by the same length from u to v, 65 { 66 // here to be written out if statement 67 Road [v] = + Road [u]; // that the v is the shortest path will add the number to the number of shortest path u strip 68 IF (Total [u] + SP [v]> Total [v]) // update recovery and path number, because the number of rescue is the second title keyword 69 { 70 path [v] = U; // If updated, then it must be a precursor v U 71 is Total [v] = Total [U] + SP [v]; 72 } 73 is } 74 } 75 } 76 } 77 } 78 // output function 79 void output () 80 { 81 the printf ( " % D% D \ n- " , Road [D], Total [D]); 82 int TEMP = D; 83 Stack <int>ss; 84 while (path[temp]!=-1) 85 { 86 ss.push(temp); 87 temp=path[temp]; 88 } 89 ss.push(s); 90 while (!ss.empty()) 91 { 92 printf("%d%c",ss.top(),ss.size()==1? '\n':' '); 93 ss.pop(); 94 } 95 } 96 int main() 97 { 98 scanf("%d%d%d%d",&n,&m,&s,&d); 99 for (int i=0;i<n;i++) 100 scanf("%d",&sp[i]); 101 init(); 102 for (int i=0;i<m;i++) 103 { 104 int x,y,len; 105 scanf("%d%d%d",&x,&y,&only); 106 City temp1, temp2 of; 107 temp1.e = Y; temp1.len = len; 108 temp2.e = X; temp2.len = len; 109 VE [X] .push_back (temp1); // undirected graph 110 VE [Y] .push_back (temp2 of); 111 } 112 DJST (); 113 Output (); 114 return 0 ; 115 }