Water Container System

아직 제출이 없습니다메모리 제한1024 MB

문제

There is a water container system with N\mathbf{N} identical containers, which can be represented as a tree, where each container is a vertex. The containers are connected to each other with N1\mathbf{N}-1 bidirectional pipes. Two containers connected to each other are always placed on adjacent levels. Formally, if two containers aa and bb are connected to each other, then level_alevel_b=1|level\_a - level\_b | = 1. Container 11 is placed at the bottommost level. Each container is connected to exactly one container on the level below (the only exception is container 11, which has no connections below it), but can be connected to zero or more containers on the level above. The maximum capacity of each container is 11 liter, and initially all the containers are empty. Assume that the pipe has a capacity of 00 liters. In other words, they do not store any water, but only allow water to pass through them in any direction.

Consider the following diagram which is an example of a water container system:

The first level of the system consists of a single container, container 11 (root). Container 11 is connected to container 22 and container 33, which are present in the above level, level 22. Container 22 is also connected to container 44, which is present at level 33.

You are given Q\mathbf{Q} queries. Each query contains a single integer ii which represents a container. For each query, add an additional 11 liter of water in container ii.

The following diagram illustrates the flow of the water in the system in different conditions:

In step 11, after adding 11 liter of water in container 33, the water flows downward because the water containers at the lower level are still empty.

In step 22, after adding 11 liter of water in container 33, the water flows downward, but as the container 11 is already filled completely, the water is distributed evenly between water containers 22 and 33.

In step 33, after adding 11 liter of water in container 33, the water containers 22 and 33 are completely filled.

In step 44, after adding 11 liter of water in container 33, the water is pushed up to water container 44, which is then completely filled.

As illustrated in the example above, containers at the same level will have the same amount of water. Find the number of water containers that are completely filled after processing all the queries.

입력

The first line of the input gives the number of test cases, T\mathbf{T}. T\mathbf{T} test cases follow.

The first line of each test case contains the two integers N\mathbf{N} and Q\mathbf{Q}, where N\mathbf{N} is the number of containers and Q\mathbf{Q} is the number of queries.

The next N1\mathbf{N}-1 lines contain two integers ii and jj (1i,jN1 \le i, j \le \mathbf{N}, and iji ≠ j) meaning that the ii-th water container is connected to the jj-th water container.

Each of the next Q\mathbf{Q} lines contain a single integer ii (1iN1 \le i \le \mathbf{N}) that represents the container to which 11 liter of water should be added.

출력

For each test case, output one line containing Case #x: y, where xx is the test case number (starting from 1) and yy is the number of water containers that are completely filled after processing all the queries.

제한

  • 1T1001 \le \mathbf{T} \le 100.
  • 1QN1 \le \mathbf{Q} \le \mathbf{N}.
  • It is guaranteed that the given water container system is a tree.