Describe
On Halloween morning, Little Hi and Little ho, after a one-hour debate, finally decided how to spend a meaningful day-they decided to go to the haunted house!
After a number of hours in front of the haunted house, Little Hi and Little Ho, who had just entered the haunted house, were hungry, so they decided to use the map they had received before the door to find the shortest route to the end.
There are a total of n locations in the Haunted house, numbered 1, respectively. N, there are some road connections between these n locations, there may be multiple roads connected between the two locations, but there is no road where both ends are the same location. So little hi and Little ho at least how many miles to walk out of the haunted house to eat things?
Hint: Order! The order is the key. Input
Each test point (input file) has and has only one set of test data.
In a set of test data:
The 1th Act is 4 integers n, M, S, T, respectively, indicating the number of places in the haunted house and the number of roads, the number of the entrance (also a location), and the number of the exit (also a location).
The next M-line, each line describes a road: where the I behavior of three integers u_i, v_i, Length_i, indicates that there is a road length v_i between the place numbered U_i and the place numbered length_i.
For 100% of data, meet N<=10^3,m<=10^4, 1 <= length_i <= 10^3, 1 <= S, T <= N, and S not equal to T.
For 100% of the data, meeting little Hi and Little ho is always a way to get to the exit via the road marked on the map from the entrance.
Output
For each set of test data, output an integer ans, which means that little hi and Little ho are going to walk out of the haunted house at least.
Sample input
5 23 5 41 2 7082 3 1123 4 7214 5 3395 4 9601 5 8492 5 981 4 992 4 252 1 2003 1 1463 2 1061 4 8604 1 7955 4 4795 4 2803 4 3 411 4 6224 2 3622 3 4154 1 9042 1 7162 5 575
Sample output
123
There may be multiple paths in one point to the other, and the minimum value can be resolved at input.
1#include <cstdio>2#include"iostream"3#include <algorithm>4 using namespacestd;5 6 Const intINF =1<< -;7 Const intMAX =10010;8 intn,m;9 intMap[max][max];Ten intVis[max],cast[max]; One A voidDijkstra (intSinte) - { - intI,j,min,pos; the for(i =0; i<n; i++) -Cast[i] =Map[s][i]; -Cast[s] =0; -Vis[s] =1; + for(i =1; i<n; i++) - { +Min =inf; A for(j =0; j<n; J + +) at { - if(Cast[j]<min &&!)Vis[j]) - { -pos =J; -Min =Cast[j]; - } in } - if(min = =inf) to Break; +Vis[pos] =1; - for(j =0; j<n; J + +) the { * if(Cast[pos]+map[pos][j]<cast[j] &&!Vis[j]) $CAST[J] = cast[pos]+Map[pos][j];Panax Notoginseng } - } the } + A intMain () the { + inti,j,s,e,x,y; -CIN >> N >> m >> s >>e; $S--, e--; $ for(i =0; i<n; i++) - for(j =0; j<n; J + +) -MAP[I][J] =inf; the for(i =0; i< m; i++) - {Wuyi inta,b,c; theCin >> a >> b >>C; -A--, b--; Wu if(C <Map[a][b]) -MAP[A][B] = Map[b][a] =C; About } $ Dijkstra (s,e); -cout << Cast[e] <<Endl; - return 0; -}
code June
Dijkstra (Hihocoder 23rd week)