시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 (추가 시간 없음) 1024 MB169956.250%

문제

Doomsday is near! Or at least that’s what your brother is telling you. In his preparations he has constructed a clever network of well concealed food depots and water depots far out in a mountainous region. You are in your base, and the alarm goes off: how quickly can you fetch both food and water supplies?

입력

The first line contains four integers $n$, $m$, $w$, $f$, where $1 \leq n \leq 50\,000$ is the number of hidden locations, $0 \leq m \leq 150\,000$ is the number of trails in the network, $1 \leq w \leq n$ is the number of water depots in total, and $1 \leq f \leq n$ is the number of food depots in total. Your base is at location $0$. The second line contains $w$ space-separated integers $u_1, u_2, \ldots, u_w$, which represents the (distinct) locations of the water depots ($0 \leq u_i < n$ for each $i$). The third line contains $f$ space-separated integers $v_1, v_2, \ldots, v_f$, which represents the (distinct) locations of the food depots ($0 \leq v_i < n$ for each $i$).

The next $m$ lines each describe a (bidirectional) trail in the network. The $i^{\text{th}}$ such line contains three space-separated integers $a_i$, $b_i$ and $t_i$ indicating that there is a trail between location $a_i$ and $b_i$ which takes $t_i$ hours to traverse ($0 \leq a_i, b_i < n$ and $0 \leq t_i < 100$ for each $i$).

출력

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

예제 입력 1

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

예제 출력 1

14

출처

Contest > Bergen Open > Bergen Open 2021 D번

  • 문제를 만든 사람: Simen Hornnes