题库练习 Hamiltonian Spanning Tree
← 上一题 下一题 →

A10243 | Hamiltonian Spanning Tree

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

A group of $n$ cities is connected by a network of roads. There is an undirected road between every pair of cities, so there are ![](/uploads/acgo/image/05c9b299bb1e8607_a459d5d6d9cd.jpeg) roads in total. It takes exactly $y$ seconds to traverse any single road.

A spanning tree is a set of roads containing exactly $n-1$ roads such that it's possible to travel between any two cities using only these roads.

Some spanning tree of the initial network was chosen. For every road in this tree the time one needs to traverse this road was changed from $y$ to $x$ seconds. Note that it's not guaranteed that $x$ is smaller than $y$ .

You would like to travel through all the cities using the shortest path possible. Given $n$ , $x$ , $y$ and a description of the spanning tree that was chosen, find the cost of the shortest path that starts in any city, ends in any city and visits all cities exactly once.

输入格式

The first line of the input contains three integers $n$ , $x$ and $y$ ( $2<=n<=200000,1<=x,y<=10^{9}$ ).

Each of the next $n-1$ lines contains a description of a road in the spanning tree. The $i$ -th of these lines contains two integers $u_{i}$ and $v_{i}$ ( $1<=u_{i},v_{i}<=n$ ) — indices of the cities connected by the $i$ -th road. It is guaranteed that these roads form a spanning tree.

输出格式

Print a single integer — the minimum number of seconds one needs to spend in order to visit all the cities exactly once.

输入输出样例

输入 #1
5 2 3
1 2
1 3
3 4
5 3
输出 #1
9
输入 #2
5 3 2
1 2
1 3
3 4
5 3
输出 #2
8
C++ 编辑器
输入
输出