You are a given a tree of
vertices. The -th vertex has two things assigned to it — a value and a range . It is guaranteed that .
You perform the following operation exactly once:
- Pick a (possibly empty) subset of vertices of the tree. must satisfy the additional condition that no two vertices in are directly connected by an edge, i.e, it is an independent set.
- Then, for each , you can set to any value in the range (endpoints included).
Your task is to minimize the value of over all unordered pairs such that and are connected by an edge.
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains a single integer , the number of vertices.
- The next lines describe the values of the vertices. The -th of these lines contains three space-separated integers , , and respectively
- The next lines describe the edges. The -th of these lines contains two space-separated integers and , denoting an edge between and .
Output Format
For each test case, output on a new line the minimum possible value as described in the statement.
Constraints
- for each
- The sum of over all test cases won't exceed .
Sample Input 1
2
3
1 1 1
2 3 3
3 3 3
1 2
1 3
4
3 3 4
1 3 5
2 2 2
2 2 2
1 2
2 3
2 4
Sample Output 1
3
1
Explanation
Test case : Set the value of to . The answer is .
Test case : Set the value of to . The answer is .
No comments:
Post a Comment