#P8855. [POI 2002 R1] 商务旅行

[POI 2002 R1] 商务旅行

Problem Description

A merchant in the capital of a certain place often needs to travel to other towns for business, and he will follow his own route.

There are NN towns, and the capital is numbered 11. The merchant starts from the capital, and there are roads connecting the towns.

If there is a direct road between any two towns, traveling between them costs one unit of time. Starting from the capital, it is possible to reach any town.

Please find the merchant's shortest travel time.

Input Format

The first line contains an integer NN, the number of towns.

The next N1N - 1 lines each contain two integers aa and bb, indicating that there is a road connecting town aa and town bb.

Next is an integer MM, followed by MM lines. Each line contains the index of a town that the merchant needs to visit in order.

Output Format

Output one line containing the merchant's shortest travel time.

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

Hint

Constraints: 1N300001 \le N \le 30000. It is guaranteed that the road network contains no cycles.

Translated by ChatGPT 5