| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 서브태스크 참고 (추가 시간 없음) | 1024 MB | 30 | 19 | 17 | 65.385% |
There is a water container system with $\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 $\mathbf{N}-1$ bidirectional pipes. Two containers connected to each other are always placed on adjacent levels. Formally, if two containers $a$ and $b$ are connected to each other, then $|level_a - level_b | = 1$. Container 1ドル$ is placed at the bottommost level. Each container is connected to exactly one container on the level below (the only exception is container 1ドル,ドル 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 1ドル$ liter, and initially all the containers are empty. Assume that the pipe has a capacity of 0ドル$ 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 1ドル$ (root). Container 1ドル$ is connected to container 2ドル$ and container 3ドル,ドル which are present in the above level, level 2ドル$. Container 2ドル$ is also connected to container 4ドル,ドル which is present at level 3ドル$.
You are given $\mathbf{Q}$ queries. Each query contains a single integer $i$ which represents a container. For each query, add an additional 1ドル$ liter of water in container $i$.
The following diagram illustrates the flow of the water in the system in different conditions:
In step 1ドル,ドル after adding 1ドル$ liter of water in container 3ドル,ドル the water flows downward because the water containers at the lower level are still empty.
In step 2ドル,ドル after adding 1ドル$ liter of water in container 3ドル,ドル the water flows downward, but as the container 1ドル$ is already filled completely, the water is distributed evenly between water containers 2ドル$ and 3ドル$.
In step 3ドル,ドル after adding 1ドル$ liter of water in container 3ドル,ドル the water containers 2ドル$ and 3ドル$ are completely filled.
In step 4ドル,ドル after adding 1ドル$ liter of water in container 3ドル,ドル the water is pushed up to water container 4ドル,ドル 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, $\mathbf{T}$. $\mathbf{T}$ test cases follow.
The first line of each test case contains the two integers $\mathbf{N}$ and $\mathbf{Q},ドル where $\mathbf{N}$ is the number of containers and $\mathbf{Q}$ is the number of queries.
The next $\mathbf{N}-1$ lines contain two integers $i$ and $j$ (1ドル \le i, j \le \mathbf{N},ドル and $i ≠ j$) meaning that the $i$-th water container is connected to the $j$-th water container.
Each of the next $\mathbf{Q}$ lines contain a single integer $i$ (1ドル \le i \le \mathbf{N}$) that represents the container to which 1ドル$ liter of water should be added.
For each test case, output one line containing Case #x: y, where $x$ is the test case number (starting from 1) and $y$ is the number of water containers that are completely filled after processing all the queries.
시간 제한: 20 초
시간 제한: 60 초
2 1 1 1 3 2 1 2 1 3 1 2
Case #1: 1 Case #2: 1
In Sample Case #1, there is $\mathbf{N} = 1$ water container. The number of completely filled water containers after adding 1ドル$ liter of water in container 1ドル$ is 1ドル$.
In Sample Case #2, there are $\mathbf{N} = 3$ water containers. The number of completely filled water containers after processing all the queries is 1ドル$.
After adding 1ドル$ liter of water in container 1ドル$: container 1ドル$ is completely filled, and the remaining containers are empty.
After adding 1ドル$ liter of water in container 2ドル$: container 1ドル$ is completely filled, and containers 2ドル$ and 3ドル$ are partially filled.
2 4 4 1 2 1 3 2 4 3 3 3 3 5 2 1 2 5 3 3 1 2 4 4 5
Case #1: 4 Case #2: 1
In Sample Case #1, there are $\mathbf{N} = 4$ water containers. The number of completely filled water containers after processing all the queries is 4ドル,ドル which is already explained in the problem statement.
In Sample Case #2, there are $\mathbf{N} = 5$ water containers. The number of completely filled water containers after processing all the queries is 1ドル$.
After adding 1ドル$ liter of water in container 4ドル$: container 1ドル$ is completely filled, and the remaining containers are empty.
After adding 1ドル$ liter of water in container 5ドル$: container 1ドル$ is completely filled, containers 2ドル$ and 3ドル$ are partially filled, and the remaining containers are empty.
Contest > Google > Kick Start > Google Kick Start 2022 > Round F B번