Formica Sokobanica
Time limit3sMemory limit512 MB
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.
문제
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 and , the numbers of rooms and nuts. They satisfy and . Rooms are numbered from 1 to . The ant starts in room 1.
Each of the next lines contains two integers and , meaning a tunnel connects rooms and . Here , , and . No two tunnels connect the same pair of rooms.
Each of the last lines contains an integer (), the room that holds a nut. All 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.