CF1822F.Gardening Friends

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Two friends, Alisa and Yuki, planted a tree with nn vertices in their garden. A tree is an undirected graph without cycles, loops, or multiple edges. Each edge in this tree has a length of kk . Initially, vertex 11 is the root of the tree.

Alisa and Yuki are growing the tree not just for fun, they want to sell it. The cost of the tree is defined as the maximum distance from the root to a vertex among all vertices of the tree. The distance between two vertices uu and vv is the sum of the lengths of the edges on the path from uu to vv .

The girls took a course in gardening, so they know how to modify the tree. Alisa and Yuki can spend cc coins to shift the root of the tree to one of the neighbors of the current root. This operation can be performed any number of times (possibly zero). Note that the structure of the tree is left unchanged; the only change is which vertex is the root.

The friends want to sell the tree with the maximum profit. The profit is defined as the difference between the cost of the tree and the total cost of operations. The profit is cost of the tree minus the total cost of operations.

Help the girls and find the maximum profit they can get by applying operations to the tree any number of times (possibly zero).

输入格式

The first line of the input contains one integer tt ( 1t1041 \le t \le 10^4 ) — the number of test cases.

The description of the test cases follows.

The first line of each test case contains integers nn , kk , cc ( 2n21052 \le n \le 2 \cdot 10^5 ; 1k,c1091 \le k, c \le 10^9 ) — the number of vertices in the tree, the length of each edge, and the cost of the operation.

The next n1n - 1 lines of the test case contain pairs of integers uiu_i , viv_i ( 1ui,vin1 \le u_i, v_i \le n ) — the edges of the graph. These edges form a tree.

The sum of the values of nn over all test cases does not exceed 21052 \cdot 10^5 .

输出格式

For each test case, output a single integer — the maximum profit that Yuki and Alisa can get.

输入输出样例

  • 输入#1

    4
    3 2 3
    2 1
    3 1
    5 4 1
    2 1
    4 2
    5 4
    3 4
    6 5 3
    4 1
    6 1
    2 6
    5 1
    3 2
    10 6 4
    1 3
    1 9
    9 7
    7 6
    6 4
    9 2
    2 8
    8 5
    5 10

    输出#1

    2
    12
    17
    32
首页