Codeforces Round 1075 (Div. 2)
F
Zhora the Vacuum Cleaner
Codeforces
2800
原题
← E→
翻译中…

Once upon a time, Zhora the Vacuum Cleaner found a big container with nuts that is represented by a tree with $n$ vertices. Initially, in the $i$-th vertex, there are $a_i$ nuts. What Zhora the Vacuum Cleaner likes most is eating nuts, so he decided to eat all the nuts.

翻译中…

To save electricity, the vacuum cleaner can rearrange the nuts in the container beforehand. Zhora can choose a vertex $v$ of the tree, and for every vertex $u \ne v$, in non-increasing order of the length of path $uv$, if $u$ contains at least one nut, one nut from $u$ moves into the closest vertex to $v$ among $u$'s adjacent vertices. This operation requires $p$ electricity units.

翻译中…

After performing several such operations (possibly none), Zhora the Vacuum Cleaner eats all the nuts from every vertex, spending $q$ electricity units per every vertex that contains nuts.

翻译中…

What is the minimum amount of electricity units required to eat all the nuts?

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The first line of each test case contains three integers $n$, $p$, and $q$ ($2 \le n \le 10^5$, $0 \le p, q \le 10^6$) — the number of vertices in the container's tree and the required amounts of electricity for operations of types 1 and 2, respectively.

翻译中…

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le 10^6$) — the quantities of nuts in the vertices.

翻译中…

Each of the next $n - 1$ lines of each test case contains two integers $u$ and $v$ ($1 \le u, v \le n, u \ne v$), representing an undirected tree edge from vertex $u$ to vertex $v$. It is guaranteed that the given edges form a tree.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.

翻译中…

Output

翻译中…

For each test case, output the minimum amount of electricity units required to eat all the nuts.

翻译中…

Note

翻译中…

In the first test case, it is best to apply the movement operation to vertex $2$, and then eat all the $4$ nuts from vertex $2$, spending $1 + 1 = 2$ electricity units in total.

翻译中…

In the second test case, it is best to apply the movement operation twice to vertex $3$, and then eat all the $5$ nuts from vertex $3$, spending $1 + 1 + 100 = 102$ electricity units in total.

翻译中…

In the third test case, it is best just to eat all the nuts from vertices $1,2,4,5$, spending $10 + 10 + 10 + 10 = 40$ electricity units.

翻译中…

In the fourth test case, it is best to apply the movement operation twice to vertex $2$, and then eat all the nuts from vertex $2$, spending $6$ electricity units in total.

翻译中…

样例

Input #1
6
4 1 1
1 1 1 1
1 2
2 3
2 4
5 1 100
1 1 1 1 1
1 2
2 3
3 4
4 5
5 9 10
4 8 0 8 4
1 3
2 3
3 4
3 5
4 1 4
0 3 1 1
2 1
3 1
4 3
5 21 93
0 0 64 4 87
2 1
3 1
4 3
5 1
4 5 8
2 3 0 8
4 3
2 3
3 1
Output #1
2
102
40
6
270
24
InputCopy OutputCopy
题目信息
题号
2189F
时间限制
2 s
内存限制
256 MB
标签
数据结构
DFS 及类似
动态规划
贪心
模拟
排序
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。