Defense Tower
题号:NC52821
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 32 M,其他语言64 M
Special Judge, 64bit IO Format: %lld

题目描述

In ICPCCamp, there are n cities and (n - 1) (bidirectional) roads between cities.
The i-th road is between the a_i-th and b_i-th cities.
It is guaranteed that cities are connected.

In the i-th city, there is a defense tower with power p_i.
The tower protects all cities with a road directly connected to city i.
However, the tower in city i does not protect city i itself.

Bobo would like to destroy all defense towers.
When he tries to destroy the tower in city i, any not-destroyed tower protecting city i will deal damage whose value equals to its power to Bobo.

Find out the minimum total damage Bobo will receive if he chooses the order to destroy the towers optimally.

输入描述:

The input contains at most 30 sets. For each set:
The first line contains an integer n ().
The second line contains n integers ().
The i-th of the last (n - 1) lines contains 2 integers a_i, b_i ().

输出描述:

For each set, an integer denotes the minimum total damage.
示例1

输入

复制
3
1 2 3
1 2
2 3

输出

复制
3
示例2

输入

复制
3
1 100 1
1 2
2 3

输出

复制
2