#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 towns, and the capital is numbered . 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 , the number of towns.
The next lines each contain two integers and , indicating that there is a road connecting town and town .
Next is an integer , followed by 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: . It is guaranteed that the road network contains no cycles.
Translated by ChatGPT 5