当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

5682:zxa and leaf

题目描述
zxa have an unrooted tree with $n$ nodes, including $(n-1)$ undirected edges, whose nodes are numbered from $1$ to $n$. The degree of each node is defined as the number of the edges connected to it, and each node whose degree is $1$ is defined as the leaf node of the tree.

zxa wanna set each node's beautiful level, which must be a positive integer. His unrooted tree has $m(1\leq m\leq n)$ leaf nodes, $k(1\leq k\leq m)$ leaf nodes of which have already been setted their beautiful levels, so that zxa only needs to set the other nodes' beautiful levels.

zxa is interested to know, assuming that the ugly level of each edge is defined as the absolute difference of the beautiful levels between two nodes connected by this edge, and the ugly level of the tree is the maximum of the ugly levels of **all the edges on this tree**, then what is the minimum possible ugly level of the tree, can you help him?
输入解释
The first line contains an positive integer $T$, represents there are $T$ test cases.

For each test case:

The first line contains two positive integers $n$ and $k$, represent the tree has $n$ nodes, $k$ leaf nodes of which have already been setted their beautiful levels.

The next $(n-1)$ lines, each line contains two distinct positive integers $u$ and $v$, repersent there is an undirected edge between node $u$ and node $v$.

The next $k$ lines, each lines contains two positive integers $u$ and $w$, repersent node $u$ is a leaf node, whose beautiful level is $w$.

There is a blank between each integer with no other extra space in one line.

It's guaranteed that the input edges constitute a tree.

$1\leq T\leq 10,2\leq n\leq 5\cdot10^4,1\leq k\leq n,1\leq u,v\leq n,1\leq w\leq 10^9$
输出解释
For each test case, output in one line a non-negative integer, repersents the minimum possible ugly level of the tree.
输入样例
2
3 2
1 2
1 3
2 4
3 9
6 2
1 2
1 3
1 4
2 5
2 6
3 6
5 9
输出样例
3
1

提示
If you need a larger stack size, please use #pragma comment(linker, "/STACK:102400000,102400000") and submit your solution using C++.
来自杭电HDUOJ的附加信息
Recommend wange2014

该题目是Virtual Judge题目,来自 杭电HDUOJ

题目来源 BestCoder Round #83

源链接: HDU-5682

最后修改于 2020-10-25T23:24:46+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
5000/2500MS(Java/Others) 65536/65536K(Java/Others)