시간 제한메모리 제한제출정답맞힌 사람정답 비율
20 초 (추가 시간 없음) 1024 MB111100.000%

문제

The countryside of Kickstartia consists of V villages (labelled from 1 to V), connected by V-1 bidirectional roads (labelled from 1 to V-1). The i-th road connects village Xi to village Yi. Each road connects exactly two villages, and no two roads connect the same two villages. Furthermore, there is exactly one sequence of roads that connects any two villages in Kickstartia.

Some villages are more beautiful than others. The i-th village has a beauty value of Bi. Note that it is possible for a village to have a negative beauty value!

You are going to build lighthouses in some of the villages. A village is illuminated if there is a lighthouse built in it, or there is a lighthouse built in a village that is directly connected to it by a road.

You may build as many or as few (even zero) lighthouses as you like. What is the maximum possible sum of beauty values of illuminated villages you can obtain?

입력

The first line of the input gives the number of test cases, TT test cases follow. Each test case begins with a line containing the integer V, the number of villages. The second line contains V integers. The i-th of these is Bi, the beauty value of the i-th village.

Then, V-1 lines follow. The i-th line gives Xi and Yi, indicating the i-th road connects village Xi to village Yi.

출력

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 possible sum of beauty values of illuminated villages you can obtain.

제한

  • 1 ≤ T ≤ 100.
  • 2 ≤ V ≤ 105.
  • -105 ≤ Bi ≤ 105 for all i.
  • 1 ≤ XiYi ≤ V for all i.
  • Xi ≠ Yi for all i.
  • (XiYi) ≠ (XjYj) for all i ≠ j.
  • There is exactly one sequence of roads connecting every pair of villages.

Test Set 1 (13점)

  • 1 ≤ V ≤ 15.

Test Set 2 (29점)

  • 1 ≤ V ≤ 105.

예제 입력 1

3
9
-10 4 -10 8 20 30 -2 -3 7
1 4
2 4
4 3
9 4
9 8
7 5
6 7
7 9
4
-2 20 20 20
1 2
1 3
1 4
5
-5 -10 8 -7 -2
5 4
4 3
3 2
2 1

예제 출력 1

Case #1: 67
Case #2: 58
Case #3: 0

힌트

In Sample Case #1, you can place a lighthouse in villages 2 and 7. This illuminates villages 2, 4, 5, 6, 7 and 9, for a total beauty of 4 + 8 + 20 + 30 + (-2) + 7 = 67. There are other possible ways to place lighthouses to achieve this total beauty.

In Sample Case #2, you can place a lighthouse in villages 1, 2 and 3. This illuminates villages 1, 2, 3 and 4, for a total beauty of (-2) + 20 + 20 + 20 = 58. There are other possible ways to place lighthouses to achieve this total beauty.

In Sample Case #3, the best you can do is to place no lighthouses at all! This illuminates no villages for a total beauty of 0.

채점 및 기타 정보

  • 예제는 채점하지 않는다.