아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Electricity

면접 대비

시간 제한40초메모리 제한1024 MB

요약
각 정점에 용량이 있는 트리에서 시작 정점 하나를 골랐을 때, 용량이 더 작은 이웃으로만 전기가 전파된다. 전기를 받는 정점 수의 최댓값을 구한다.
난이도

보통10점 중 6점

유형
트리, DFS, 그리디
정답자
아직 제출이 없습니다

문제

Ben works as an engineer in a city with N\mathbf{N} electric junctions. These junctions form a network and can be visualised as a connected graph with N\mathbf{N} vertices and N−1\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. A_i\mathbf{A\_i} is the electric capacity of the ii-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 ii-th junction receives electricity, then it will also get transmitted to all the junctions directly connected to the ii-th junction whose capacity is strictly less than A_i\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, T\mathbf{T}. T\mathbf{T} test cases follow.

The first line of each test case contains an integer N\mathbf{N} which represents the number of junctions in the city.

The next line contains N\mathbf{N} integers. The ii-th integer is A_i\mathbf{A\_i}, which is the electric capacity of the ii-th junction.

The next N−1\mathbf{N}-1 lines each contain two integers X_i\mathbf{X\_i} and Y_i\mathbf{Y\_i}, meaning that the junctions X_i\mathbf{X\_i} and Y_i\mathbf{Y\_i} are directly connected to each other.

출력

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 maximum number of junctions that can receive electricity.

제한

  • 1≤T≤1001 \le \mathbf{T} \le 100.
  • 1≤A_i≤1091 \le \mathbf{A\_i} \le 10^9, for all ii.
  • 1≤X_i,Y_i≤N1 \le \mathbf{X\_i}, \mathbf{Y\_i} \le \mathbf{N}, for all ii.
  • All the junctions are part of a single connected network.

예제1

  1. 예제 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
    
    예상 출력
    Case #1: 5
    Case #2: 3