Input
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≤T≤10,2≤n≤5?104,1≤k≤n,1≤u,v≤n,1≤w≤109
Output
For each test case, output in one line a non-negative integer, repersents the minimum possible ugly level of the tree.
Sample Input
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
Sample Output
3
1
Hint
If you need a larger stack size, please use #pragma comment(linker, "/STACK:102400000,102400000") and submit your solution using C++.
题意:一棵树n个点,其中有一些点已经有权值,现在给剩下的点安排权值,使得树中相邻两点的之差绝对值的最大值最小。
二、解题思路