P9864 [POI 2021/2022 R2] age
Background
Translated from [POI2021~2022R2 Day1T1](https://szkopul.edu.pl/problemset/problem/weKRWGa1NgLNHT1WLDo5ohuH/statement/)。
Description
There is a country with $n$ cities. We can view it as a tree with $n-1$ roads. One day, you suddenly decide to place $k$ people in different cities. The people and their movement must satisfy the following rules:
- Each day, only one person may move, and they can move to a neighboring city connected by a road.
- Suppose there are two people $a,b$. If city $i$ has been visited by $a$, then $b$ is not allowed to visit city $i$.
Initially, you know the positions of the people. Each person starts in a different city, and that city is considered “already visited”. You need to plan a valid visiting scheme.
Find the minimum number of days needed so that all cities are visited by someone.
Input Format
The first line contains two integers $n,k\ (1 \leq n \leq 5 \times 10^5, 1 \leq k \leq n)$。
The second line contains $k$ integers, representing the initial positions of the people.
Then follow $n-1$ lines, each describing a road $(a_i,b_i)\ (1 \leq a_i,b_i \leq n)$。
Output Format
Output the minimum number of days。
Explanation/Hint
Explanation of the sample:

The subtasks are as follows:
| Subtask ID | Special property | Score |
| :----------: | :----------: | :----------: |
| $1$ | $n \leq 10$ | $6$ |
| $2$ | $n \leq 20$ | $13$ |
| $3$ | $n \leq 2000$ | $27$ |
| $4$ | $k=1$ | $10$ |
| $5$ | $k=2$ | $7$ |
| $6$ | The input is a chain | $7$ |
| $7$ | No special property | $30$ |
Subtask $0$ is the sample。
Translated by ChatGPT 5