P27345 [AtCoder] Traveling Salesman Problem
NOI
题目描述

Problem Description

There are $ N $ towns in the Kingdom of Sunuke.

There are $ M $ roads in the kingdom, and the $ i $-th road connects towns $ u_i $ and $ v_i $ bidirectionally. To use a road once, you need to pay a toll of $ 1 $ yen. It is known that you can start from any town and reach any other town by traversing some roads.

Takaaha, a traveling merchant in the kingdom, is currently in town $ s $ and wants to conduct transactions in $ K $ towns $t_1, t_2, \ldots, t_K$.

Starting from town $ s $, what is the minimum total toll Takaaha needs to pay to visit each of the $ K $ towns at least once? It is not necessary to return to town $ s $ eventually.

Note that when the same road is used multiple times, you need to pay the toll each time.

Input Format

The input is given from the standard input in the following format:

$ N $ $ M $ $ u_1 $ $ v_1 $ $ u_2 $ $ v_2 $ $\vdots$ $ u_M $ $ v_M $ $ s $ $ K $ $ t_1 $ $ t_2 $ $\ldots$ $ t_K $

Output Format

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

Sample Input and Output

Sample Input #1

3 2
1 2
2 3
2
2
1 3

Sample Output #1

3

Sample Input #2

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

Sample Output #2

4

Notes/Hints

Note

Discussion of this problem is prohibited until 18:00 JST on June 6, 2020. If mentioned, it may result in a claim for damages. It is okay to publish the total score or certification level after the exam, but please refrain from disseminating information about which problems were solved.

Constraints

  • All inputs are integers.
  • $2 \leq N \leq 10^5$
  • $N - 1 \leq M \leq 10^5$
  • $1 \leq u_i < v_i \leq N$
  • $(u_i, v_i) \neq (u_j, v_j)$ when $i \neq j$
  • $1 \leq s \leq N$
  • $1 \leq K \leq \min (N - 1, 16)$
  • $1 \leq t_i \leq N$
  • $t_i \neq t_j$ when $i \neq j$
  • $s \neq t_i$

Sample Explanation 1

First, move from town $ 2 $ to town $ 1 $, then return to town $ 2 $, and finally move to town $ 3 $. This way, you can visit towns $ 1 $ and $ 3 $ with a total toll of $ 3 $ yen.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 2 1 2 2 3 2 2 1 3
样例输出
3