This page is still under construction.

Parts of this page are still being built. What you see may change.

Doomsday

Time limit5sMemory limit1024 MB

Summary
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 nn, mm, ww, ff, where 1≤n≤50 0001 \leq n \leq 50\,000 is the number of hidden locations, 0≤m≤150 0000 \leq m \leq 150\,000 is the number of trails in the network, 1≤w≤n1 \leq w \leq n is the number of water depots in total, and 1≤f≤n1 \leq f \leq n is the number of food depots in total. Your base is at location 00. The second line contains ww space-separated integers u_1,u_2,…,u_wu\_1, u\_2, \ldots, u\_w, which gives the distinct locations of the water depots (0≤u_i<n0 \leq u\_i < n for each ii). The third line contains ff space-separated integers v_1,v_2,…,v_fv\_1, v\_2, \ldots, v\_f, which gives the distinct locations of the food depots (0≤v_i<n0 \leq v\_i < n for each ii).

The next mm lines each describe one bidirectional trail in the network. The ithi^{\text{th}} such line contains three space-separated integers a_ia\_i, b_ib\_i, t_it\_i, meaning there is a trail between location a_ia\_i and location b_ib\_i that takes t_it\_i hours to traverse (0≤a_i,b_i<n0 \leq a\_i, b\_i < n and 0≤t_i<1000 \leq t\_i < 100 for each ii).

Output

Output a single integer, the minimum number of hours needed to fetch both food and water and bring them back to base.

Examples1

  1. Example 1

    Input
    7 7 2 2
    3 6
    4 5
    0 1 3
    0 2 1
    1 3 3
    1 4 1
    2 5 2
    2 6 10
    4 5 1
    
    Expected output
    14