HDU-2112 HDU day-Short Circuit Problem

Source: Internet
Author: User
HDU today

Time Limit: 15000/5000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 5634 accepted submission (s): 1369

With the help of Problem description, Haidong Group has finally passed the crisis. Since then, HDU has been developing smoothly. By 2050, the Group has already reached a considerable scale, it is said that it entered the Qianjiang meat silk Economic Development Zone's top 500. At this time, the xhd couple also retired to the second line, and they bought a house in taoyao village, Xupu town, zhushu city, Fengjing, and began to settle down in their later years.
After staying for a while, Xu still does not know much about the local traffic. Sometimes it is very depressing. If you want to go to a certain place, you don't know what bus to take, where to get a taxi, or where to get off. (In fact, Xu has his own car, but he must be happy with the people, this is Xu's character ).
Mr. Xu often asked me in poor English: "Can you help me ?". Looking at his confused and helpless eyes, can you help him with enthusiasm?
Please help him reach his destination in the shortest time (assuming that each bus stops at the start station and end station, and will start at any time ).

 

There are multiple groups of input data. The first line of each group is the total number of buses N (0 <=n <= 10000 );
In the second line, there is Xu's location start, his destination end;
Next there are n rows, each row has the station name s, station name E, and the time integer t from S to E (0 <t <100) (Each place name is a string of no more than 30 characters ).
Note: The number of physical names in a group of data cannot exceed 150.
If n =-1, the input ends.

 

Output: If Xu can always reach the destination, the output time is the shortest; otherwise, "-1" is output ".

 

Sample Input
6xiasha westlakexiasha station 60xiasha ShoppingCenterofHangZhou 30station westlake 20ShoppingCenterofHangZhou supermarket 10xiasha supermarket 50supermarket westlake 10-1

 

Sample output
50 hint: the best route is: Xiasha-> shoppingcenterofhangzhou-> supermarket-> although Westlake occasionally gets lost, but with your help ** and **, we have lived a happy life. -The end of the entire drama ――

 

Authorlgx

 

Sourceacm programming _ final examination (the time has been set !!)

 

Recommendlcy

 

 

 

The novelty of this question is how to translate a string into a point abstracted by a number. You can use s [I] [] to abstract the point. I is used to represent the first few points, and the rest can be solved by using objective Scal.

# Include <stdio. h> # include <string. h> # include <stdlib. h> # include <math. h ># include <string> # define INF 0x3fffffffint S = 1, E = 2, temp; char s [200] [35]; int dis [200]; int visit [200]; int t; // Number of edges int map [200] [200]; int find (char * A) {int I; for (I = 1; I <temp; I ++) {If (strcmp (s [I], a) = 0) return I;} strcpy (s [temp], ); return temp ++;} int literal Scal () {int I; Int J; int n = temp-1; for (I = 1; I <= N; I ++) dis [I] = inf; DIS [s] = 0; For (j = 1; j <n; j ++) {Int T = inf; int Pos; for (I = 1; I <= N; I ++) {If (! Visit [I] & T> dis [I]) {T = dis [I]; Pos = I ;}} visit [POS] = 1; if (Pos = 2) return dis [E]; for (I = 1; I <= N; I ++) {If (! Visit [I] & map [POS] [I] & dis [I]> dis [POS] + map [POS] [I]) {dis [I] = dis [POS] + map [POS] [I] ;}}return dis [e] ;}int main () {char a [35], B [35], Sta [35], end [35]; int I; int m; while (scanf ("% d", & T) & T! =-1) {temp = 1; char o = getchar (); memset (S, 0, sizeof (s); memset (visit, 0, sizeof (visit )); memset (MAP, 0, sizeof (MAP); scanf ("% S % s", STA, end); s = find (STA); E = find (end ); for (I = 1; I <= T; I ++) {scanf ("% S % d", a, B, & M ); int K = find (A), KK = find (B); map [k] [Kk] = m; Map [Kk] [k] = m ;} int ans = Hangzhou Scal (); If (ANS! = Inf) printf ("% d \ n", ANS); elseprintf ("-1 \ n") ;}return 0 ;}

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.