CF2189F.Zhora the Vacuum Cleaner

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Once upon a time, Zhora the Vacuum Cleaner found a big container with nuts that is represented by a tree with nn vertices. Initially, in the ii-th vertex, there are aia_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 vv of the tree, and for every vertex u≠vu \ne v, in non-increasing order of the length of path uvuv, if uu contains at least one nut, one nut from uu moves into the closest vertex to vv among uu's adjacent vertices. This operation requires pp electricity units.

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

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

从前,吸尘器卓拉发现了一个装满坚果的大容器,该容器被表示为一棵含有 nn 个顶点的树。初始时,第 ii 个顶点上有 aia_i 颗坚果。卓拉最喜爱的事情就是吃坚果,因此他决定吃掉所有坚果。

为了节省电量,吸尘器可以在吃坚果之前重新分配容器中的坚果。卓拉可以选择树上的一个顶点 vv,然后对每个顶点 u≠vu \ne v,按路径 uvuv 的长度非递增顺序处理:若 uu 中至少有一颗坚果,则从 uu 中取出一颗坚果,并将其移入 uu 的所有邻接顶点中距离 vv 最近的那个顶点。执行一次这样的操作需要消耗 pp 单位电量。

在执行若干次(可能为零次)上述操作后,卓拉将吃掉每个顶点上的全部坚果,对每个含有坚果的顶点额外消耗 qq 单位电量。

吃掉所有坚果所需的最少电量是多少?

输入格式

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

The first line of each test case contains three integers nn, pp, and qq (2≤n≤1052 \le n \le 10^5, 0≤p,q≤1060 \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 nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤1060 \le a_i \le 10^6) — the quantities of nuts in the vertices.

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

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含三个整数 nn、pp 和 qq(2≤n≤1052 \le n \le 10^5,0≤p,q≤1060 \le p, q \le 10^6)——分别表示容器树中的顶点数,以及类型 1 和类型 2 操作所需的电量。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai≤1060 \le a_i \le 10^6)——表示各顶点中坚果的数量。

每个测试用例接下来的 n−1n - 1 行中,每行包含两个整数 uu 和 vv(1≤u,v≤n1 \le u, v \le n,u≠vu \ne v),表示一条连接顶点 uu 与顶点 vv 的无向树边。保证所给边构成一棵树。

保证所有测试用例的 nn 之和不超过 10510^5。

输出格式

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

对于每个测试用例,输出吃完所有坚果所需的最少电量单位数。

输入输出样例

  • 输入#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

    输出#1

    2
    102
    40
    6
    270
    24

说明/提示

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

In the second test case, it is best to apply the movement operation twice to vertex 33, and then eat all the 55 nuts from vertex 33, spending 1+1+100=1021 + 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,51,2,4,5, spending 10+10+10+10=4010 + 10 + 10 + 10 = 40 electricity units.

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

在第一个测试用例中,最优策略是将移动操作应用于顶点 22,然后吃掉顶点 22 上的全部 44 颗坚果,总共消耗 1+1=21 + 1 = 2 单位电量。

在第二个测试用例中,最优策略是将移动操作两次应用于顶点 33,然后吃掉顶点 33 上的全部 55 颗坚果,总共消耗 1+1+100=1021 + 1 + 100 = 102 单位电量。

在第三个测试用例中,最优策略是直接吃掉顶点 1,2,4,51,2,4,5 上的所有坚果,总共消耗 10+10+10+10=4010 + 10 + 10 + 10 = 40 单位电量。

在第四个测试用例中,最优策略是将移动操作两次应用于顶点 22,然后吃掉顶点 22 上的所有坚果,总共消耗 66 单位电量。

输入解题思路,AI测评打分。不知道怎么写?

首页