The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | May 2017 |
| Last Sign in: | 399 Weeks Ago, 1 Day Ago |
| Questions Answered: | 66690 |
| Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
A thief is trying to escape the holds of the police through a city. Let’s assume we represent our city by a weighted undirected connected graph(with no self-loops and multi-edges) with N nodes and M edges.
Â
Thief is currently at vertex numbered S and needs to reach vertex numbered D. Thief moves with constant speed VT = 1.
Â
K policemen are initially located in K distinct locations denoted by A1, A2, ... AK. Each policeman has a constant speed of VP = 1.
To help policemen, a single power booster have been provided to them. This power booster can be availed once from any one of the Q distinct ‘special’ nodes B1, B2, ... BQ. Property of this power booster being that it doubles the speed of the policeman who avails this power booster.
Note:
A policeman can choose not to avail the power booster even if he is at a ‘special’ node.
You have to print the shortest time in which thief can escape the police regardless of whatever path the police might take.
If he can’t reach the destination, output -1.
Â
Â
Â
Â
First line contains N and M, the number of nodes and number of edges respectively.
Each of the next M lines contain integers u v and w denoting an undirected edge between nodes numbered u and v, w being the weight of the edge.
Next line contains a single integer K denoting number of different policemen. Next line contains K space separated integers denoting the distinct locations A1, A2, ... AK.
Next line contains a single integer Q denoting number of ‘special’ nodes. Next line contains Q distinct space separated integers denoting the locations B1, B2, ... BQ.
Next line contains two distinct integers S and D denoting the source and destination of the thief.
Â
Â
For each test case print the minimum time required for thief to escape(if possible). Else, output -1.
Â
Â
Â
Â
Input1: 4 4 0 1 2 1 2 4 2 3 10 3 0 2 1 3 1 0 2 1 Output1: -1
Â
Input2: 4 3 0 1 2 1 2 8 1 3 10 2 2 3 2 2 3 0 1 Output2: 2
Â
Example1:
Police takes the path 3 -> 0 -> 1 availing the power booster at node 0. Even though both policeman and thief reach the destination at same time, police catches thief.
Example2:
Whichever policeman uses the power booster, thief will be able to escape in 2 seconds.
Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll