Hdu 2066 travel by one person
Travel Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission (s): 18284 Accepted Submission (s): 6358
Problem Description although caoer is a luchi (that is, the person who has been in Hangzhou for more than a year will still be lost on campus, Khan ~), However, caoer still enjoys traveling, because he will meet many people (Prince Charming, ^ 0 ^) on the road. Many things can enrich his experience, you can also see beautiful scenery ...... Caoer wants to go to many places. She wants to go to the Tokyo Tower to see the night view, go to Venice to see the movie, go to Yangmingshan to see the taro, go to New York to see the pure snow scene, go to Paris to drink coffee and write, visit Meng jiangnv in Beijing ...... The winter vacation is approaching. You can't waste it for such a long period of time. You must give yourself a good vacation, but you can't waste your training, therefore, caoer decided to go to a desired place in the shortest time! Because caoer's home is in a small town without passing by train, she can only take a train to the neighboring city ~).
There are multiple groups of Input data. The first line of each group is three integers T, S, and D, indicating that there are T routes and S are adjacent to cao'er's city, there are D places to go;
Then there are T rows. Each row has three integers a, B, and time, indicating that the driving distance between cities a and B is time hour. (1 = <(a, B) <= 1000; there may be multiple routes between a and B)
The next line T + 1 contains the number of S, indicating the city connected to cao'er's home;
The next line T + 2 has the number D, which indicates that the grass wants to go to the place.
Output outputs the shortest time for a favorite city.
Sample Input
6 2 31 3 51 4 72 8 123 8 44 9 129 10 21 28 9 10
Sample Output
9
# Include
# Include
# Include # define M 1005 # define INF 9999 using namespace std; int map [M] [M], v [M], d [M]; int n; void Dijkstra (int x) {int I, j; memset (v, 0, sizeof (v); for (I = 0; I <= n; I ++) d [I] = map [x] [I]; v [x] = 1; for (I = 1; I <= n; I ++) {int min = INF; int k; for (j = 0; j <= n; j ++) // note that the source point is 0 {if (! V [j] & d [j]
D [k] + map [k] [j]) d [j] = d [k] + map [k] [j] ;}} int main () {int T, S, D, a, B, t; int k1 [M], k2 [M]; int I, j; while (~ Scanf ("% d", & T, & S, & D) {memset (map, 0, sizeof (map); for (I = 0; I <= 1001; I ++) {for (j = 0; j <= 1001; j ++) {if (I = j) map [I] [j] = 0; elsemap [I] [j] = INF ;}} n = 0; for (I = 0; I
T) map [a] [B] = map [B] [a] = t; if (n