HDU 2066 travel by one person (Shortest circuit)
Question:
Travel by one person
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 22263 Accepted Submission (s): 7720
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
Solution:
The bare question with the most short circuit. Pay attention to the following points when setting it.
1. The distance from the start point to the adjacent point is 0.
2. for initialization, you must first find the maximum vertex or directly to 1000.
3. Bidirectional edges.
4. Obtain the shortest value between the two sides.
5. Finally, traverse and find the shortest distance among all the points you want to go.
Code:
# Include
Using namespace std; # define inf 0x3fffffff # define M 1005int dist [M], map [M] [M], n; bool mark [M]; void init () {int I, j; for (int I = 1; I
B) ans = a; else ans = B; if (ans> c) return ans; else return c;} int min (int a, int B) {if (