Logo
(追記) (追記ここまで)

26438번 - Electricity 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
40 초 (추가 시간 없음) 1024 MB14131392.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.

제한

  • 1ドル \le \mathbf{T} \le 100$.
  • 1ドル \le \mathbf{A_i} \le 10^9,ドル for all $i$.
  • 1ドル \le \mathbf{X_i}, \mathbf{Y_i} \le \mathbf{N},ドル for all $i$.
  • All the junctions are part of a single connected network.

Test Set 1 (10점)

  • 1ドル \le \mathbf{N} \le 10^3$.

Test Set 2 (15점)

  • For at most 15 cases:
    • 1ドル \le \mathbf{N} \le 2 \times 10^5$.
  • For the remaining cases:
    • 1ドル \le \mathbf{N} \le 10^3$.

예제 입력 1

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

예제 출력 1

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번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /