Codeforces Round 364 (Div. 2)
E
Connecting Universities
Codeforces
未评级
原题
← DF →
翻译中…

Treeland is a country in which there are $*n*$ towns connected by $*n* - 1$ two-way road such that it's possible to get from any town to any other town.

翻译中…

In Treeland there are $2*k*$ universities which are located in different towns.

翻译中…

Recently, the president signed the decree to connect universities by high-speed network.The Ministry of Education understood the decree in its own way and decided that it was enough to connect each university with another one by using a cable. Formally, the decree will be done!

翻译中…

To have the maximum sum in the budget, the Ministry decided to divide universities into pairs so that the total length of the required cable will be maximum. In other words, the total distance between universities in $*k*$ pairs should be as large as possible.

翻译中…

Help the Ministry to find the maximum total distance. Of course, each university should be present in only one pair. Consider that all roads have the same length which is equal to $1$.

翻译中…

Input

翻译中…

The first line of the input contains two integers $*n*$ and $*k*$ ($2 ≤ *n* ≤ 200 000$, $1 ≤ *k* ≤ *n* / 2$) — the number of towns in Treeland and the number of university pairs. Consider that towns are numbered from $1$ to $*n*$.

翻译中…

The second line contains $2*k*$ distinct integers $*u*_{1}, *u*_{2}, ..., *u*_{2*k*}$ ($1 ≤ *u*_{*i*} ≤ *n*$) — indices of towns in which universities are located.

翻译中…

The next $*n* - 1$ line contains the description of roads. Each line contains the pair of integers $*x*_{*j*}$ and $*y*_{*j*}$ ($1 ≤ *x*_{*j*}, *y*_{*j*} ≤ *n*$), which means that the $*j*$-th road connects towns $*x*_{*j*}$ and $*y*_{*j*}$. All of them are two-way roads. You can move from any town to any other using only these roads.

翻译中…

Output

翻译中…

Print the maximum possible sum of distances in the division of universities into $*k*$ pairs.

翻译中…

Note

翻译中…

The figure below shows one of possible division into pairs in the first test. If you connect universities number $1$ and $6$ (marked in red) and universities number $2$ and $5$ (marked in blue) by using the cable, the total distance will equal $6$ which will be the maximum sum in this example.

翻译中…

image

翻译中…

样例

Input #1
7 2
1 5 6 2
1 3
3 2
4 5
3 7
4 3
4 6
Output #1
6
InputCopy OutputCopy
Input #2
9 3
3 2 1 6 5 9
8 9
3 2
2 7
3 4
7 6
4 5
2 1
2 8
Output #2
9
InputCopy OutputCopy
题目信息
题号
701E
时间限制
3 s
内存限制
256 MB

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