Doomsday
Time limit5sMemory limit1024 MB
Given a weighted undirected graph, a base at 0, and sets of water and food depots, find the minimum time to visit one depot of each type and return to base.
- Level
Medium6 of 10
- Topics
- Graph, Shortest path, Greedy, Math
- Solved
- No attempts yet
Problem
Doomsday is near! Or at least that is what your brother keeps telling you. As preparation he built a clever network of well concealed food depots and water depots far out in a mountainous region. You are at your base when the alarm goes off: how quickly can you fetch both food and water supplies?
Input
The first line contains four integers , , , , where is the number of hidden locations, is the number of trails in the network, is the number of water depots in total, and is the number of food depots in total. Your base is at location . The second line contains space-separated integers , which gives the distinct locations of the water depots ( for each ). The third line contains space-separated integers , which gives the distinct locations of the food depots ( for each ).
The next lines each describe one bidirectional trail in the network. The such line contains three space-separated integers , , , meaning there is a trail between location and location that takes hours to traverse ( and for each ).
Output
Output a single integer, the minimum number of hours needed to fetch both food and water and bring them back to base.