QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 1024 MB Points totaux : 100

#6248. Hakuna Matata

Statistiques

On the island of Fluke, there are $k$ different tribes living in $k$ different locations. The map of the island of Fluke is a connected graph with $n$ locations (vertices) and $n-1$ roads (edges).

Due to ideological differences that have arisen between the tribes on this island, a civil war has begun. Each day, every tribe expands to all locations adjacent to the roads they currently control and captures those locations. If two tribes reach the same location, or if a tribe reaches a location that has already been captured by another tribe, these two tribes negotiate and consequently unite, acting as a single tribe from then on (it is possible for more than two tribes to unite at the same moment!).

As a spy for the World Peace Organization, your task is to use the graph of the island of Fluke provided in the input to find the first day of the war when all $k$ tribes unite with each other.

Input

The first line of the input contains two integers $n$ and $k$, representing the number of locations and the number of tribes on the island, respectively. Each of the next $n-1$ lines contains two integers $u_i$ and $v_i$, representing the two endpoints of the $i$-th edge of the island's graph. Then, $k$ distinct integers are given in a single line, where the $i$-th number is the starting vertex $a_i$ of the $i$-th tribe in the input graph. It is guaranteed that the input graph satisfies the necessary conditions and is valid.

Output

Print the minimum number of days that must pass for all tribes to unite and reach an agreement.

Constraints

  • $1 \le n \le 10^6$
  • $1 \le k, a_i \le n$

Examples

Input 1

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

Output 1

1

Input 2

4 2
1 2
2 3
3 4
1 4

Output 2

2

Input 3

8 3
1 2
2 3
3 4
4 5
5 6
3 7
7 8
2 6 8

Output 3

2

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.