HDU today--hdu2112

Source: Internet
Author: User

HDU Today

Time limit:15000/5000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 19680 Accepted Submission (s): 4632


Problem description through the brocade SAC Help, Sea East group finally passed the crisis, from now on, HDU development has been downwind, to 2050 years, the group has been quite scale, said to enter the Qianjiang pork economic Development Zone 500 strong. At this time, Xhd couple also retreated to the second line, and in the beautiful scenery of Zhuji knots Pu Zhen Tao Yao bought a house, began to comfort old age.
This lived for a period of time, Xu always to the local traffic still do not know very much. Sometimes very depressed, want to go to a place and do not know what bus to take, where to change, where to get off (in fact, Xu always own a car, but must have fun with the people, this is Xu General character).
Xu always asks the lame English question: Can you help me? Look at his confused and helpless eyes, enthusiastic can you help him?
Please help him to arrive at his destination in the shortest possible time (assuming that each bus stops at starting point and terminus and is open at all times).

Input data has multiple groups, the first row of each group is the total number of buses N (0<=n<=10000);
The second line has the location of the total Xu, start, his destination end;
Then there are n rows, each with the station name S, the station name E, and the time integer T (0<t<100) from S to E (each place name is a string with a length of not more than 30).
Note: No more than 150 place names in a set of data.
If N==-1, indicates the end of the input.

Output if Xu always arrives at the destination, outputs the shortest time; otherwise, output "-1".

Sample Input6xiasha Westlakexiasha Station 60xiasha Shoppingcenterofhangzhou 30station Westlake 20ShoppingCenterofHangZhou supermarket 10xiasha supermarket 50supermarket Westlake 10-1

Sample Output50 hint:the Best route is:xiasha->shoppingcenterofhangzhou->supermarket->westlake though occasionally lost, But because of your help * * and * * Still live a happy life. --the whole ending--the newly learned map converts a string directly into a number!
1#include <cstdio>2#include <cstring>3#include <algorithm>4#include <map>5#include <string>6 #defineMAX 0x3f3f3f3f7 using namespacestd;8 intma[ the][ the];9 intd[ the],n,t;Ten voidDijkstra () One { A     inti,j,min,mark,used[ the]; -      for(i=1; i<=t;i++) -     { theused[i]=0; -d[i]=ma[1][i]; -     } -d[1]=0; +used[1]=1; -      for(i=1; i<=t;i++) +     { Amark=-1; atmin=MAX; -          for(j=1; j<=t;j++) -         { -             if(!used[j]&&d[j]<min) -             { -min=D[j]; inmark=J; -             } to         } +         if(mark==-1) -          Break; theused[mark]=1; *          for(j=1; j<=t;j++) $         {Panax Notoginseng             if(!used[j]&&d[j]>d[mark]+Ma[mark][j]) -d[j]=d[mark]+Ma[mark][j]; the         } +     } A } the  +  -  $ intMain () $ { -     inti; -     Chars1[ the],s2[ the]; themap<string,int>Q; -      while(SCANF ("%d", &n), n!=-1)Wuyi     { thememset (Ma,max,sizeof(MA)); - q.clear (); Wuscanf"%s%s", S1,S2); -q[s1]=1; Aboutq[s2]=2; $         intflag=0, A; -         if(strcmp (s1,s2) = =0) -flag=1;//Start endpoint same tag, output 0 -t=3; A          for(i=0; i<n;i++) +         { thescanf"%s%s%d",s1,s2,&a); -             if(!q[s1]) q[s1]=t++; $             if(!q[s2]) q[s2]=t++;//Convert to Digital process thema[q[s1]][q[s2]]=ma[q[s2]][q[s1]]=A; the         } the Dijkstra (); the         if(flag) -printf"0\n"); in         Else if(d[2]==MAX) theprintf"-1\n"); the         Else Aboutprintf"%d\n", d[2]); the     } the return 0;  the}

HDU today--hdu2112

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.