#P9864. [POI 2021/2022 R2] age
[POI 2021/2022 R2] age
Background
Translated from POI2021~2022R2 Day1T1。
Problem Description
There is a country with cities. We can view it as a tree with roads. One day, you suddenly decide to place 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 . If city has been visited by , then is not allowed to visit city .
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 integers, representing the initial positions of the people.
Then follow lines, each describing a road 。
Output Format
Output the minimum number of days。
6 2
2 6
1 2
2 3
2 4
5 4
5 6
5
Hint
Explanation of the sample:

The subtasks are as follows:
| Subtask ID | Special property | Score |
|---|---|---|
| The input is a chain | ||
| No special property |
Subtask is the sample。
Translated by ChatGPT 5