There is a rooted tree of $$$n$$$ vertices. The vertices are numbered from $$$1$$$ to $$$n$$$ (both inclusive) and the tree is rooted at $$$1$$$. All of the $$$n$$$ vertices are white at the beginning and you need to color all the vertices black.
To help you achieve the goal we will provide you with $$$n$$$ types of operations, numbered from $$$0$$$ to $$$(n - 1)$$$ (both inclusive). Operation $$$i$$$ ($$$0 \le i \le n - 1$$$) requires you to first select a vertex $$$u$$$, then color all the vertices $$$v$$$ satisfying the following conditions black:
The cost of performing operation $$$i$$$ once is given as $$$a_i$$$. A vertex can be colored more than once and all operations can be performed any number of times. Calculate the minimum total cost to color all the vertices black.
There are multiple test cases. The first line of the input contains an integer $$$T$$$ indicating the number of test cases. For each test case:
The first line contains an integer $$$n$$$ ($$$2 \le n \le 10^5$$$) indicating the size of the tree.
The second line contains $$$n$$$ integers $$$a_0, a_1, \cdots, a_{n-1}$$$ ($$$1 \le a_i \le 10^9$$$) where $$$a_i$$$ indicates the cost of performing operation $$$i$$$ once.
For the following $$$(n - 1)$$$ lines, the $$$i$$$-th line contains two integers $$$u_i$$$ and $$$v_i$$$ ($$$1 \le u_i, v_i \le n$$$, $$$u_i \neq v_i$$$) indicating an edge connecting vertices $$$u_i$$$ and $$$v_i$$$.
It's guaranteed that the sum of $$$n$$$ of all test cases will not exceed $$$3 \times 10^5$$$.
For each test case output one line containing one integer indicating the minimum total cost to color the tree black.
3410 15 40 11 22 32 4510 5 1 100 10001 22 32 44 541000 200 10 81 22 33 4
35 17 1218
The first sample test case is illustrated below. The answer is $$$15 + 10 + 10 = 35$$$.
The second sample test case is illustrated below. The answer is $$$5 + 10 + 1 + 1 = 17$$$.
| Название |
|---|


