AlgoUniversity
  • Go Back
Discussion
Footwear :

Author

Ujjwal Rana

Difficulty Level : Medium

Submissions : 560

Asked In : Flipkart

Marks :10

: 5 | : 0

A footwear company has N outlets having unique id from $$$0$$$ to $$$N-1$$$. The outlets are connected using the bi directional roads directly or via other outlets. There is a cost of stock transfer between the directly connected outlets. Initially, the warehouses were established at K outlets. As the demand of the products increases unexpectedly during the festival seasons, so the stocks need to be transferred quickly among the warehouses. The company has decided to provide the trucks to transport the stock from one warehouse to another but it puts extra overhead on the company. The company has decided to start the truck between the closest warehouses initially. The company wants to find the minimum stock transfer cost between any two warehouses which will be incurred on the company. Write an algorithm to find the minimum stock transfer cost between any two warehouses which will be overhead on the company.

Input

The first line of the input consists of two space-separated integers - numOutlets and numWarehouses, representing the number of outlets ($$$2\leq N \leq 500$$$) and the number of warehouses($$$2 \leq K \leq N$$$). The next line consists of K space separated integers warehouse D[0], warehouse D[1]..., warehouse/D[K-1], representing the ids where the warehouses were established initially. The next line consists of an integer - directConnection, representing the number of direct connections among outlets ($$$X$$$). The next $$$X$$$ lines consists of three space-separated integers - $$$A, B, C$$$ representing the id of the directly connected outlets ($$$A$$$ and $$$B$$$) and the cost of stock transport $$$1\leq C \leq 1300$$$ between outlet $$$A$$$ and $$$B$$$.

Output

Print an integer representing the minimum stock transfer cost between any two warehouses.

Examples

Input
6 3
1 3 4
7
0 1 10
0 4 7
1 3 12
3 5 3
1 5 10
4 2 2
2 5 3
Output
8
Input
5 4
0 2 3 4
6
0 1 1249
0 3 209
0 4 609
1 3 73
2 4 703
3 4 1048
Output
209

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.