Under construction

Still being built. Things may change

Formica Sokobanica

Time limit3sMemory limit512 MB

Summary
In a tree-shaped nest with nuts, count the rooms the ant can enter when each entry pushes the nut into an adjacent empty room.
Level

Medium7 of 10

Topics
Tree, DFS, Greedy
Solved
No attempts yet

문제

A new ant species, Formica sokobanica, was recently discovered. Entomologists are interested in it because of its unusual habit. These ants do not form colonies. Each individual builds its own private nest and keeps its food, nuts, inside.

A nest is made of many small rooms connected by tunnels. Each room is only a little larger than a nut, leaving just enough space for air to flow. An ant cannot enter a room that holds a nut. The tunnels fit a nut exactly, so a nut must never be left in a tunnel, or air could not flow through.

To enter a room with a nut, the ant must push the nut into one of the vacant rooms adjacent to it, through the tunnel connecting them. If the only vacant adjacent room is the one the ant came from, the nut cannot be pushed, and the ant cannot enter the room.

Dr. Myrmink, one of the entomologists, drew a diagram of a typical nest. The diagram shows which rooms hold nuts and which room the ant starts in. Count the rooms the ant can reach and enter.

Pushing a nut into one vacant room may make some rooms unreachable, while pushing it into another room may keep them reachable. Many combinations of choices are possible. Count every room that can be reached by at least one combination of choices. The ant's starting room has no nut, and the nest has no cycles.

입력

The first line contains nn and mm, the numbers of rooms and nuts. They satisfy 1≤n≤2×1051 \le n \le 2 \times 10^5 and 0≤m<n0 \le m < n. Rooms are numbered from 1 to nn. The ant starts in room 1.

Each of the next n−1n-1 lines contains two integers xix_i and yiy_i, meaning a tunnel connects rooms xix_i and yiy_i. Here 1≤xi≤n1 \le x_i \le n, 1≤yi≤n1 \le y_i \le n, and xi≠yix_i \ne y_i. No two tunnels connect the same pair of rooms.

Each of the last mm lines contains an integer aka_k (2≤ak≤n2 \le a_k \le n), the room that holds a nut. All aka_k are distinct.

n m
x1 y1
.
.
.
xn-1 yn-1
a1
.
.
.
am

출력

Print a single integer on one line: the number of rooms the ant can reach and enter.

Examples4

  1. Example 1

    Input
    7 2
    1 2
    2 3
    3 4
    4 5
    5 6
    5 7
    2
    4
    
    Expected output
    2
    
  2. Example 2

    Input
    8 2
    1 2
    2 3
    3 4
    2 5
    5 6
    6 7
    2 8
    2
    6
    
    Expected output
    7
    
  3. Example 3

    Input
    7 3
    1 2
    2 3
    3 4
    3 5
    4 6
    5 7
    2
    4
    5
    
    Expected output
    2
    
  4. Example 4

    Input
    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
    
    Expected output
    9