#P1592C. Bakry and Partitioning
Bakry and Partitioning
No submission language available for this problem.
Description
Bakry faced a problem, but since he's lazy to solve it, he asks for your help.
You are given a tree of nodes, the -th node has value assigned to it for each from to . As a reminder, a tree on nodes is a connected graph with edges.
You want to delete at least , but at most edges from the tree, so that the following condition would hold:
For every connected component calculate the bitwise XOR of the values of the nodes in it. Then, these values have to be the same for all connected components.
Is it possible to achieve this condition?
Each test contains multiple test cases. The first line contains the number of test cases . Description of the test cases follows.
The first line of each test case contains two integers and .
The second line of each test case contains integers .
The -th of the next lines contains two integers and (, ), which means that there's an edge between nodes and .
It is guaranteed that the given graph is a tree.
It is guaranteed that the sum of over all test cases doesn't exceed .
For each test case, you should output a single string. If you can delete the edges according to the conditions written above, output "YES" (without quotes). Otherwise, output "NO" (without quotes).
You can print each letter of "YES" and "NO" in any case (upper or lower).
Input
Each test contains multiple test cases. The first line contains the number of test cases . Description of the test cases follows.
The first line of each test case contains two integers and .
The second line of each test case contains integers .
The -th of the next lines contains two integers and (, ), which means that there's an edge between nodes and .
It is guaranteed that the given graph is a tree.
It is guaranteed that the sum of over all test cases doesn't exceed .
Output
For each test case, you should output a single string. If you can delete the edges according to the conditions written above, output "YES" (without quotes). Otherwise, output "NO" (without quotes).
You can print each letter of "YES" and "NO" in any case (upper or lower).
Samples
Note
It can be shown that the objection is not achievable for first, third, and fifth test cases.
In the second test case, you can just remove all the edges. There will be connected components, each containing only one node with value , so the bitwise XORs will be for all of them.
In the fourth test case, this is the tree: .
You can remove an edge
The bitwise XOR of the first component will be, (where denotes the bitwise XOR).
The bitwise XOR of the second component will be, .