On a weighted undirected graph, find the vertex with no McDonald's or Starbucks whose distance to the nearest McDonald's is at most x, to the nearest Starbucks at most y, and whose two distances sum to the minimum.
Medium6GraphShortest pathDynamic programmingNo attempts yetTime limit1sMemory limit256 MBSanghyuk lives in Anyang and is worn out after four years of commuting, so he wants to find a house in Seoul. The house he wants meets all three conditions below.
The commute has worn Sanghyuk down and he cannot decide on a house. Solve the problem for him. A map of the area he is moving to is given as a weighted graph, and the McDonald's and Starbucks locations are given as vertex numbers. Write a program that prints the sum of the two shortest distances for the house Sanghyuk wants. Every vertex that has neither a McDonald's nor a Starbucks has a house.

In the map above, a square is a vertex with a McDonald's, a star is a vertex with a Starbucks, and each circle is a vertex with a house. When x is 6 and y is 4, the house that answers the question is vertex 6. Its shortest distance to a McDonald's is 2 and its shortest distance to a Starbucks is 4, so the sum is 6. Vertex 7 also meets both conditions, but its two shortest distances are 6 and 2 for a sum of 8, which is larger than the value at vertex 6, so it is not the answer. Vertices 2, 3 and 4 fail to meet both conditions at once, so none of them can be the answer.
The first line has the number of vertices V(3≤V≤10000) and the number of roads E(0≤E≤300000). Each of the next E lines has three integers u, v and w in that order. They mean there is a road of weight w(1≤w<10000) between vertices u and v(1≤u,v≤V). u and v are different, and several roads may join the same pair of vertices.
The next line has the number of McDonald's locations M(1≤M≤V−2) and the threshold x(1≤x≤100000000), and the line after it has the M vertex numbers that have a McDonald's. The next line has the number of Starbucks locations S(1≤S≤V−2) and the threshold y(1≤y≤100000000), and the line after it has the S vertex numbers that have a Starbucks.
Print the sum of the shortest distance to a McDonald's and the shortest distance to a Starbucks for the house Sanghyuk wants. If no house meets the conditions, print -1.