Sandy the Squirrel has hit the jackpot by discovering that a secret golden walnut exists in one of the walnut trees that she frequents.
The walnut tree in question is composed of nodes numbered to that are fully connected by branches. In her search, Sandy will start at node and find the golden walnut at one of the other nodes. Then, she must then get back to node to use the teleporter that she hid there.
After finding the treasure, Sandy will alert other squirrels positioned at distinct starting nodes on the tree that will attempt to yoink it from her. At the start of every second, she will move to the next node on the simple path to node . At the end of every second, each of the squirrels may move to any adjacent node or stay where they are. Multiple squirrels may occupy the same node. If, at any point in time (including the start), Sandy is on the same node as another squirrel, they will yoink the treasure. As soon as Sandy is on node without any other squirrels there, she will be able to teleport away.
Since Sandy doesn't know the node that the golden walnut is located on, she would like you to help her find the number of nodes that it could be on such that she can make it back safely even if all the squirrels move optimally.
Constraints
Subtask 1 [20%]
Subtask 2 [80%]
No further constraints.
Input Specification
The first line of input will contain two space-separated integers, and .
The next lines will each contain two space-separated integers, and , the two nodes that the th branch joins.
The next lines will each contain one integer, , the starting location of the th squirrel.
Output Specification
Output one integer, the number of nodes that the golden walnut could be hidden on such that Sandy can make it back safely.
Sample Input 1
7 1
1 3
2 6
3 4
3 5
5 6
4 7
7
Sample Output 1
3
Explanation for Sample Output 1
Sandy can make it back safely starting from nodes , , and .
Sample Input 2
5 2
1 2
1 3
1 4
1 5
1
4
Sample Output 2
0
Comments