Limits 3s, 512 MB

Poga is a war victim who lost everyone dear to her in war. Now, she leads a team of veterans who try to stop wars with minimum violence. But to do that, sometimes there is no option but to go a bit extreme.

Armed Combat Mercenaries (ACM) is a group of private soldiers who promote wars for their own profit. So, Poga and her group has set out to destroy their whole network to minimize their actions. ACM's network is in the same format as that of a tree. A tree is an acyclic undirected connected graph. For ease of work, Poga is planning strategies based on some calculation and processing of the tree.

Inside each vertex of the tree, there is a number and node 1 is the root of the tree. The cost of the whole tree can be defined as AX2+BAX^2 + B where AA and BB are two constants Poga knows from beforehand and XX is the sum of all the values of the vertices.

Now, if you cuts some edge of the tree, the tree will be split into 2 parts, each with its own cost. She is allowed to make as many cuts as she wishes. But all the cuts must be on same path from root in the original tree. That means, no two cut parts’ roots can have a lowest common ancestor that is not either of the two roots. Now, cutting this way, Poga can make many parts of the tree, find the cost of each part and sum them. What is the minimum sum can Poga make this way? Help her out find the answer, this will surely help in reducing wars!

Formally, given a rooted tree with weighted vertices, edges can be cut with the rule that all cuts must be on same path from root. Each cut splits the tree into 2 parts. There can be 0 or more cuts. Cost of each cut part is AX2+BAX^2 + B where XX is sum of all weights in the cut part and AA, BB will be given as input. Your task is to minimize sum of costs of all cut parts.

Input

Input starts with an integer TT (1T601 \le T \le 60) denoting number of test cases.

Each case starts with 3 integers NN, AA, BB. NN (1N500001 \le N \le 50000) is the number of vertices and AA (0A100000 \le A \le 10000), BB (106B106-10^6 \le B \le 10^6) is defined in problem description. In next line, NN numbers will be given, ii-th number (0i-th number1000 \le \texttt{i-th number} ≤ 100) represents the value of vertex ii.

Then, in each of the next N1N-1 lines, 2 integers UU VV (1U,VN1 \le U, V \le N, U!=VU != V) will be given denoting the 2 nodes connecting an edge of the tree. It is certain that the tree is a valid tree with all nodes connected and root is node 1.

Output

In a single line, print the minimum cost as asked in the problem statement.

Do this for each test case.

Sample

InputOutput
2
4 2 3
1 2 3 4
1 2
2 3
2 4
4 2 100
1 2 3 4
1 2
2 3
2 4
93
300

Dataset is huge. Use faster I/O.

Submit

Login to submit.

Statistics

44% Solution Ratio
ZeronfinityEarliest, Mar '18
underdogFastest, 1.1s
YouKnowWhoLightest, 9.7 MB
IOI_StfuFfsShortest, 2605B
Toph uses cookies. By continuing you agree to our Cookie Policy.