M - Real Traveling Salesman Editorial /

Time Limit: 2.5 sec / Memory Limit: 1024 MB

配点 : 66

注意

この問題に対する言及は、2020/6/6 18:00 JST まで禁止されています。言及がなされた場合、賠償が請求される可能性があります。 試験後に総合得点や認定級を公表するのは構いませんが、どの問題が解けたかなどの情報は発信しないようにお願いします。

問題文

スーヌケ王国には NN 個の街があります。

王国には MM 本の道が存在していて、ii 番目の道は、街 uiu_i, viv_i を双方向に繋いでいます。 ある道を 11 回利用するためには、通行料として 11 円を払う必要があります。 任意の街から出発して、いくつかの道を経由することで任意の街に辿り着けることが分かっています。

王国の行商人であるタカーハ氏は現在街 ss にいて、これから KK 個の街 t1,t2,,tKt_1, t_2, \ldots, t_K で取引をしたいと思っています。

ss から出発して KK 個の街それぞれを少なくとも 11 回は訪れるために、タカーハ氏が払う必要のある通行料の合計は最小で何円でしょうか。 最終的に街 ss に戻ってくる必要はありません。

同じ道を複数回利用するとき、その都度通行料を払う必要があることに注意してください。

制約

  • 入力は全て整数である。
  • 2N1052 \leq N \leq 10^5
  • N1M105N - 1 \leq M \leq 10^5
  • 1ui<viN1 \leq u_i < v_i \leq N
  • iji \neq j のとき (ui,vi)(uj,vj)(u_i, v_i) \neq (u_j, v_j)
  • 1sN1 \leq s \leq N
  • 1Kmin(N1,16)1 \leq K \leq \min (N - 1, 16)
  • 1tiN1 \leq t_i \leq N
  • iji \neq j のとき titjt_i \neq t_j
  • stis \neq t_i

入力

入力は以下の形式で標準入力から与えられる。

NN MM
u1u_1 v1v_1
u2u_2 v2v_2
\vdots
uMu_M vMv_M
ss
KK
t1t_1 t2t_2 \ldots tKt_K

出力

タカーハ氏が払う必要のある通行料の合計の最小値を整数として出力せよ。


入力例 1Copy

Copy
3 2
1 2
2 3
2
2
1 3

出力例 1Copy

Copy
3

まず街 22 から街 11 に移動して、その後再び街 22 へと戻り、次に街 33 へと移動することで、 合計 33 円の通行料で街 11 と街 33 を訪れることができます。


入力例 2Copy

Copy
5 5
1 2
1 3
1 4
1 5
2 3
1
3
2 3 5

出力例 2Copy

Copy
4

Score : 66 points

Warning

Do not make any mention of this problem until June 6, 2020, 6:00 p.m. JST. In case of violation, compensation may be demanded. After the examination, you can reveal your total score and grade to others, but nothing more (for example, which problems you solved).

Problem Statement

The Kingdom of Soonuke has NN towns.

There are MM roads in the kingdom. The ii-th road connects Town uiu_i and viv_i bidirectionally. You need to pay the toll of 11 yen each time you use a road. We know that any town can be reached from any town by using some number of roads.

Takaaha, a merchant, is now at Town ss and wants to make transactions in KK towns t1,t2,,tKt_1, t_2, \ldots, t_K

What is the minimum total toll Takaaha needs to pay when he starts at Town ss and visit each of the KK towns at least once? He does not need to come back to Town ss in the end.

Note that using the same road multiple times will cost you the toll that number of times.

Constraints

  • All values in input are integers.
  • 2N1052 \leq N \leq 10^5
  • N1M105N - 1 \leq M \leq 10^5
  • 1ui<viN1 \leq u_i < v_i \leq N
  • If iji \neq j, (ui,vi)(uj,vj)(u_i, v_i) \neq (u_j, v_j).
  • 1sN1 \leq s \leq N
  • 1Kmin(N1,16)1 \leq K \leq \min (N - 1, 16)
  • 1tiN1 \leq t_i \leq N
  • If iji \neq j, titjt_i \neq t_j.
  • stis \neq t_i

Input

Input is given from Standard Input in the following format:

NN MM
u1u_1 v1v_1
u2u_2 v2v_2
\vdots
uMu_M vMv_M
ss
KK
t1t_1 t2t_2 \ldots tKt_K

Output

Print the minimum total toll Takaaha needs to pay, as an integer.


Sample Input 1Copy

Copy
3 2
1 2
2 3
2
2
1 3

Sample Output 1Copy

Copy
3

If we go from Town 22 to Town 11, then go back to Town 22, then go to Town 33, we can visit the towns 11 and 33 with the total toll of 33 yen.


Sample Input 2Copy

Copy
5 5
1 2
1 3
1 4
1 5
2 3
1
3
2 3 5

Sample Output 2Copy

Copy
4


2025-04-25 (Fri)
23:05:23 +00:00