HDU Travel for 20,661 people

Source: Internet
Author: User

Topic Connection

http://acm.hdu.edu.cn/showproblem.php?pid=2066

A person's travel 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

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 home adjacent to the city of $s$, grass son want to go where there are $d$;
Then there is $t$ line, each line has three integer $a,b,time$, indicating $a,\ b$ between the city is $time$4 hours; $ (1 \leq (A, b) \leq 1000;a,b$ may have multiple paths)
The next $t+1$ line has the number of $s$, indicating the city connected with the grass family;
The next $t+2$ line has the number of $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 3
1 3 5
1 4 7
2 8 12
3 8 4
4 9 12
9 10 2
1 2
8 9 10

Sample Output

9

Shortest-circuit:

1#include <algorithm>2#include <iostream>3#include <cstdlib>4#include <cstring>5#include <cstdio>6#include <vector>7#include <queue>8#include <map>9 usingstd::min;Ten usingstd::cin; One usingstd::cout; A usingStd::endl; - usingStd::find; - usingStd::sort; the usingstd::p air; - usingstd::vector; - usingStd::multimap; - usingstd::p riority_queue; + #definePB (E) push_back (e) - #defineSZ (c) (int) (c). Size () + #defineMP (A, b) Make_pair (A, B) A #defineAll (c) (c). Begin (), (c). End () at #defineITER (c) Decltype ((c). Begin ()) - #defineCLS (arr,val) memset (arr,val,sizeof (arr)) - #defineCpresent (c, E) (Find (All (c), (e))! = (c). End ()) - #defineRep (i, n) for (int i = 0; i < (int) (n); i++) - #defineTR (c, I) for (ITER (c) i = (c). Begin (); I! = (c). end (); ++i) - Const intN =10010; intypedef unsignedLong Longull; - structP { to     intW, v; +Pinti =0,intj =0): W (i), V (j) {} -InlineBOOL operator< (ConstP &a)Const { the         returnW >A.W; *     } $ };Panax Notoginseng structNode {intTo , W, next;}; - structDijkstra { the Node G[n]; +     inttot, Head[n], dist[n]; AInlinevoidinit () { thetot =0, CLS (Head,-1); +     } -InlinevoidAdd_edge (intUintVintW) { $G[tot] = {V, W, Head[u]}; Head[u] = tot++; $     } -InlinevoidBuiltintN) { -         intu, V, W; the Rep (i, N) { -scanf" %d%d%d", &u, &v, &W);Wuyi Add_edge (U, V, W), Add_edge (V, U, W); the         } -     } WuInlinevoidDijkstra (vector<int> &St) { -CLS (Dist,0x3f); AboutPriority_queue<p>Q; $ Rep (i, Sz (ST)) { -Q.push (P (0, St[i])); -Dist[st[i]] =0; -         } A          while(!Q.empty ()) { +P T =q.top (); Q.pop (); the             intU =T.V; -             if(Dist[u] < T.W)Continue; $              for(inti = Head[u]; ~i; i =G[i].next) { the                 int&w =dist[g[i].to]; the                 if(W > Dist[u] +G[I].W) { theW = dist[u] +G[I].W; the Q.push (P (w, g[i].to)); -                 } in             } the         } the     } AboutInlinevoidWorkintSintd) { the         intV, ans =0x3f3f3f3f; thevector<int>A, B; the          while(s--) {scanf ("%d", &v); A.push_back (v); } +          while(d--) {scanf ("%d", &v); B.push_back (v); } - Dijkstra (A); theRep (i, Sz (B)) ans =min (ans, dist[b[i]]);Bayiprintf"%d\n", ans); the     } the }go; - intMain () { - #ifdef LOCAL theFreopen ("In.txt","R", stdin); theFreopen ("OUT.txt","w+", stdout); the #endif the     intN, S, D; -      while(~SCANF (" %d%d%d", &n, &s, &d)) { the go.init (); the go.built (n); the Go.work (S, d);94     } the     return 0; the}
View Code

HDU Travel for 20,661 people

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.