The journey of a man

Source: Internet
Author: User

Time limit:1000MS Memory Limit:32768KB 64bit IO Format:%i64d &%i64 U SubmitStatus

Description

Although the grass is a road fetish (that is, in Hangzhou electric for more than a year, incredibly still will be lost in the campus, Khan ~), but the grass is still very fond of travel, because in the journey will meet a lot of people (Prince Charming, ^0^), a lot of things, but also to enrich their experience, but also to see beautiful scenery ... Grass wants to go to many places, she wants to go to the Tokyo Tower to see the night scene, to Venice to see movies, to see the Taro on Yangmingshan, go to New York pure snow, go to Paris to drink coffee letter, to Beijing to visit Meng Jiangnu ... See the winter vacation is coming, so a large period of time, can not be wasted ah, must give yourself good put a fake, but also can not waste training ah, so grass son decided in the shortest time to a place where they want to go! Because the house of grass is in a small town, there is no train passing by, so she can only go to the neighboring city by train (poor Ah ~).

Input

The input data has more than one group, the first line of each group is three integers t,s and D, indicating that there is a T road, and the grass son of the city adjacent to the cities have s, where the grass wants to go there are D;
Then there is a T-line, each line has three integer a,b,time, indicating that the drive between A and B cities is time hours; (1=< (A, B) there may be multiple paths between <=1000;a,b)
The next line of T+1 is the number of S, which indicates the city connected with the grass family;
The next line of T+2 has a number D, indicating that the grass wants to go to the place.

Output

The shortest time the grass can go to 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
1#include <cstdio>2#include <algorithm>3#include <iostream>4#include <cstring>5 #defineINF 0XFFFFFFF6 using namespacestd;7 intt,s,d;8 intpri[1111][1111];9 intvis[1111];Ten intdis[1111]; One intbe[1111],ed[1111]; A voidDijkstraintAintb) - { -memset (Vis,0,sizeof(Vis)); thevis[a]=1; -      for(inti =1; I <= b;i++) -dis[i]=Pri[a][i]; -      for(inti =1; I <= b;i++) +     { -         intm=inf,k=-1; +          for(intj =1; J <= b;j++) A         { at             if(!vis[j]&&dis[j]<M) -m=dis[j],k=J; -         } -         if(k==-1) -         return ; -vis[k]=1; in          for(intj =1; J <= b;j++) -         { to             if(!vis[j]&&dis[j]>dis[k]+Pri[k][j]) +dis[j]=dis[k]+Pri[k][j]; -         } the     } * } $ intMain ()Panax Notoginseng { -      while(SCANF (" %d%d%d", &t,&s,&d)! =EOF) the     { +          for(inti =1; I <= +; i++)//interval open to 1111 time out, real day dog A              for(intj =1; J <= +; j + +) thePri[i][j]=i==j?0: INF;  +         inta,b,c,n=0; -          for(inti =1; I <= t;i++) $         { $scanf" %d%d%d",&a,&b,&c); -             if(max (b) >N) -n=Max (A, b); the             if(pri[a][b]>c) -pri[a][b]=pri[b][a]=C;Wuyi         } the          for(inti =1; I <= s;i++) -scanf"%d",&be[i]); Wu          for(inti =1; I <= d;i++) -scanf"%d",&ed[i]); About         intTim =INF; $          for(inti =1; I <= s;i++) -         { - Dijkstra (be[i],n); -              for(intj =1; J <= d;j++) A             { +                 if(dis[ed[j]]<Tim) theTim =Dis[ed[j]]; -             } $         } theprintf"%d\n", Tim); the          the     } the     return 0; -}
View Code

The journey of a man

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.