Hide

Problem E
Evading a Monster

A monster is chasing you in a tree with N vertices, labeled between 1 and N. Initially, the monster starts at vertex 1 and you start at vertex 2. Through careful analysis of the monster’s hunting patterns you have concluded that it will move to the (not necessarily distinct) M vertices a1, a2, , aM in order, where ai and ai+1 are adjacent in the tree for all 1iM1.

You are trying to keep away from the monster, while performing as few moves as possible. A move means moving from a vertex to an adjacent vertex. Before each of the monster’s moves, you may make any number of moves.

What is the minimal number of moves you have to make?

Input

The first line contains the integers N (2N100000) and M (1M500000), the number of vertices in the tree and the number of moves the monster performs.

The next N1 lines contains the edges of the tree. Each line consists of two integers u and v (1uvN), the vertices of the edge.

The final line contains the M numbers a1,,aM, the vertices the monster moves through (1aiN) in order. It is guaranteed that ai and ai+1 are adjacent vertices of the tree for 1iM1, and that vertices 1 and a1 are adjacent.

Output

Output a single integer, the minimal number of moves you have to perform to avoid the monster.

If avoiding the monster is impossible, output -1.

Scoring

Your solution will be tested on a set of test groups, each worth a number of points. To get the points for a test group you need to solve all test cases in the test group.

Group

Points

Constraints

1

23

N100, M500

2

27

Each vertex has degree at most 3.

3

50

No additional constraints.

Sample Input 1 Sample Output 1
4 2
1 2
2 3
1 4
2 3
-1
Sample Input 2 Sample Output 2
5 7
1 2
2 3
1 4
2 5
2 3 2 5 2 1 4
5
Hide

Please log in to submit a solution to this problem

Log in