#P14873. [ICPC 2020 Yokohama R] Formica Sokobanica

[ICPC 2020 Yokohama R] Formica Sokobanica

题目描述

A new species of ant, named Formica sokobanica, was discovered recently. It attracted entomologists’ attention due to its unique habit. These ants do not form colonies. Rather, individuals make up their private nests and keep their food, nuts, in the nests. A nest comprises a lot of small rooms connected with tunnels. They build the rooms only a little bigger than a nut leaving just enough space for air flow; they cannot enter a room with a nut in it. To save the labor, tunnels are so narrow that it exactly fits the size of a nut, and thus nuts should not be left in the tunnels to allow air flow through.

To enter a room with a nut in it, the nut has to be pushed away to any of the vacant rooms adjacent to that room through the tunnel connecting them. When no adjacent rooms are vacant except the room which the ant came from, the nut cannot be pushed away, and thus the ant cannot enter the room.

Dr. Myrmink, one of the entomologists enthused about the ants, has drawn a diagram of a typical nest. The diagram also shows which rooms store nuts in them, and which room the ant is initially in. Your job is to write a program that counts up how many rooms the ant can reach and enter. Pushing a nut into one of the vacant adjacent rooms may make some of the rooms unreachable, while choosing another room to push into may keep the rooms reachable. There can be many combinations of such choices. In such cases, all the rooms should be counted that are possibly reached by one or more choice combinations.

You may assume that there is no nut in the room the ant is initially in, and that there is no cyclic path in the nest.

输入格式

The input consists of a single test case of the following format, representing the diagram of a nest.

$$\begin{aligned} &n \ m \\ &x_1 \ y_1 \\ &\vdots \\ &x_{n-1} \ y_{n-1} \\ &a_1 \\ &\vdots \\ &a_m \end{aligned}$$

Here, nn and mm are the numbers of rooms and nuts. They satisfy 1n2×1051 \le n \le 2 \times 10^5 and 0m<n0 \le m < n. Rooms are numbered from 11 to nn. The ant is initially in the room 11.

Each of the following n1n - 1 lines has two integers xix_i and yiy_i (1in11 \le i \le n - 1) indicating that a tunnel connects rooms numbered xix_i and yiy_i. 1xin1 \le x_i \le n, 1yin1 \le y_i \le n, and xiyix_i \ne y_i hold. No two tunnels connect the same pair of rooms.

Each of the remaining mm lines has an integer aka_k (1km1 \le k \le m, 2akn2 \le a_k \le n) which indicates that the room numbered aka_k has a nut in it. The numbers aka_k's are all distinct.

输出格式

The output should be a single line containing a single integer, the number of rooms that the ant can reach and enter.

7 2
1 2
2 3
3 4
4 5
5 6
5 7
2
4
2
8 2
1 2
2 3
3 4
2 5
5 6
6 7
2 8
2
6
7
7 3
1 2
2 3
3 4
3 5
4 6
5 7
2
4
5
2
11 3
1 2
2 3
3 4
2 5
5 6
6 7
7 8
6 9
9 10
6 11
2
3
7

9