QOJ.ac

QOJ

Límite de tiempo: 2 s Límite de memoria: 256 MB Puntuación total: 100

#2660. Agents

Estadísticas

There are $k$ agents operating in Byteotia. They must visit all $n$ cities in the country, but to avoid raising the suspicions of counterintelligence:

  • Each day, exactly one agent can move from the city they are currently in to an adjacent city.
  • Each city can be visited by only one agent (though it may be visited multiple times).

The road network of Byteotia is very sparse and consists of $n-1$ roads. It is possible to travel from any city to any other city, possibly passing through other cities.

Write a program that calculates the minimum number of days required for the agents to visit all cities in the country. We assume that the cities where the agents start are already visited.

Input

The first line of input contains two integers $n$ and $k$ ($2 \le n \le 500\,000$, $1 \le k \le n$), representing the number of cities in Byteotia and the number of agents. The cities are numbered from $1$ to $n$.

The second line of input contains an increasing sequence of $k$ integers from the range $[1, n]$, representing the numbers of the cities that are the starting positions of the agents.

The next $n-1$ lines contain the description of the road network of Byteotia. Each line contains a pair of integers $a, b$ ($1 \le a, b \le n, a \neq b$), indicating that there is a road connecting cities $a$ and $b$.

Output

Your program should output a single line containing one integer representing the minimum number of days after which the agents will have visited all cities of Byteotia.

Examples

Input 1

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

Output 1

5

Note

The first agent can visit cities $2 \to 1 \to 2 \to 3$, which will take 3 days, and the second agent can visit cities $6 \to 5 \to 4$, which will take 2 days.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.