| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 40 초 (추가 시간 없음) | 1024 MB | 14 | 13 | 13 | 92.857% |
Ben works as an engineer in a city with $\mathbf{N}$ electric junctions. These junctions form a network and can be visualised as a connected graph with $\mathbf{N}$ vertices and $\mathbf{N}-1$ edges. The city is facing a power outage, due to which none of the junctions are receiving electricity, and Ben is in charge of handling the situation.
Each junction has a fixed electric capacity. $\mathbf{A_i}$ is the electric capacity of the $i$-th junction. Due to resource constraints, Ben can provide electricity to only one junction, but other junctions can receive electricity depending on their connections and capacities. If the $i$-th junction receives electricity, then it will also get transmitted to all the junctions directly connected to the $i$-th junction whose capacity is strictly less than $\mathbf{A_i}$. Transmission stops if no eligible junction is present. Help Ben determine the maximum number of junctions that can receive electricity.
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 an integer $\mathbf{N}$ which represents the number of junctions in the city.
The next line contains $\mathbf{N}$ integers. The $i$-th integer is $\mathbf{A_i},ドル which is the electric capacity of the $i$-th junction.
The next $\mathbf{N}-1$ lines each contain two integers $\mathbf{X_i}$ and $\mathbf{Y_i},ドル meaning that the junctions $\mathbf{X_i}$ and $\mathbf{Y_i}$ are directly connected to each other.
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 maximum number of junctions that can receive electricity.
2 5 1 2 3 4 3 1 3 2 3 4 3 4 5 6 1 2 3 3 1 4 3 1 3 2 3 4 4 5 1 6
Case #1: 5 Case #2: 3
In Sample Case #1, the optimal solution is to provide electricity to the fourth junction. This will transmit electricity to all the junctions eventually.
If the electricity is provided to the third junction, it will transmit it to the first and second junction, but not to the fourth junction. In that case, only three junctions can finally receive electricity.
In Sample Case #2, the optimal solution is to provide electricity to the third junction. This will transmit it to the first and second junctions. Note that electricity will not be transmitted to the fourth junction, since its capacity is not strictly less than that of the third junction.
If electricity is provided to the sixth junction, it will only be transmitted to the first junction.
If electricity is provided to the fourth junction, it will only be transmitted to the fifth junction.
Contest > Google > Kick Start > Google Kick Start 2022 > Round H C번