题目描述
"Say my Name".
Todd Alquist is being taught the process of cooking methamphetamine, but to see whether he's really capable of learning it, Walt gives him a problem to solve. Since he can't solve it, he asks you for help.
You are given a tree with $N$ vertices (numbered $1$ through $N$), rooted at the vertex $1$. There is an integer written at each vertex; for each valid $i$, the value of vertex $i$ is $A$$i$.There also exists a special integer $K$.
Choose any leaf node, denoted by $X$, and go down a simple path from $root$ to $X$.
Let $S$ denote the set of all nodes lying on the simple path from $root$ to $X$.
For all $ i $ $\epsilon$ $ S $, choose an integer $D$ $\epsilon$ $[2^{A[i]-1},2^{A[i]})$.
Informally, for every node $i$ lying on the simple path from $root$ to $X$, you have to choose an integer $D$ such that $2^{A[i]-1}\leq D < 2^{A[i]}$.
You now have to perform one of the two following operations :
- Bitwise XOR of all chosen integers.
- Bitwise AND of all chosen integers.
You have to determine whether you can choose the values in such a way that after performing one of the given operations you can get an integer equal to $K$.
- Note : A leaf is a node of the tree without any child nodes.
Determine if it is possible to obtain the value $K$ by performing the given operations.
-----Input:-----
- First line will contain $T$, number of testcases. Then the testcases follow.
- First line of each testcase contains two space separated integers $N, K$ denoting the number of nodes and the value of the special integer .
- $N-1$ lines follow , each line contains two space separated integers $u,v$ denoting an edge between $u$ and $v$.
- A single line follows containing $N$ space separated integers denoting the value of nodes.
-----Output:-----
For each testcase, output in a single line "YES"(without quotes) or "NO"(without quotes).
-----Constraints-----
- $1 \leq T \leq 10000$
- $2 \leq N \leq 5*10^5$
- $1 \leq K \leq 10^{18}$
- $1 \leq u,v \leq N$
- $1\leq A[i] \leq 64$
- Sum of $N$ over all test cases does not exceed 1e6.
-----Sample Input:-----
1
6 85
1 2
2 3
2 4
4 5
3 6
3 5 4 7 1 9
-----Sample Output:-----
YES
-----EXPLANATION:-----
There are two leaf nodes, 5 and 6
considering path from root to 5
we have nodes
1->2->4->5
we can select the values
5,26,75,1 and perform operation 1 that is XOR of all numbers to get 85
输入格式
见题面
输出格式
见题面