CF2194F1.Again Trees... (Easy Version)
提高+/省选-
通过率:0%
时间限制:1.00s
内存限制:1024MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
This is the easy version of the problem. The difference between the versions is that in this version, k≤4. You can hack only if you solved all versions of this problem.
Given a tree consisting of n vertices. Each vertex has a non-negative integer av written on it. You are also given k distinct non-negative integers b1,…,bk.
We will call a set of edges beautiful if, after removing these edges from the tree, the tree splits into connected components, where in each component the bitwise XOR of all the numbers av in that component belongs to the set b.
You need to count the number of beautiful sets of edges in the tree modulo 109+7.
这是该问题的简单版本。两个版本的区别在于,在此版本中,k≤4。仅当您解决了该问题的所有版本时,才可进行 Hack。
给定一棵包含 n 个顶点的树。每个顶点上写有一个非负整数 av。同时给定 k 个互不相同的非负整数 b1,…,bk。
我们称一组边为“优美的”,如果从树中移除这些边后,树被分割为若干连通分量,且每个连通分量内所有顶点上的数 av 的按位异或(XOR)结果均属于集合 b。
您需要计算树中优美边集的数量,结果对 109+7 取模。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤500). The description of the test cases follows.
The first line of each dataset contains two integers n and k (2≤n≤105, 1≤k≤4) — the number of vertices in the tree and the size of the set b.
The next n−1 lines describe the edges of the tree. The i-th line contains two integers vi and ui (1≤vi,ui≤n) — the numbers of the vertices connected by the i-th edge.
The next line contains n integers a1,a2,…,an (0≤ai<230) — the values written on the vertices.
The following line contains k distinct integers b1,b2,…,bk (0≤bi<230) — the elements of the set b.
It is guaranteed that the sum of n across all datasets does not exceed 105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤500)。随后是各测试用例的描述。
每个数据集的第一行包含两个整数 n 和 k(2≤n≤105,1≤k≤4)—— 分别表示树中顶点的数量以及集合 b 的大小。
接下来的 n−1 行描述树的边。第 i 行包含两个整数 vi 和 ui(1≤vi,ui≤n)—— 表示由第 i 条边连接的两个顶点的编号。
下一行包含 n 个整数 a1,a2,…,an(0≤ai<230)—— 表示写在各个顶点上的数值。
再下一行包含 k 个互不相同的整数 b1,b2,…,bk(0≤bi<230)—— 表示集合 b 的元素。
保证所有数据集中 n 的总和不超过 105。
输出格式
For each test dataset, output a single integer — the answer to the problem.
对于每个测试数据集,输出一个整数——即该问题的答案。
输入输出样例
输入#1
4 5 1 1 2 1 3 3 4 2 5 0 2 2 3 3 1 5 1 4 5 1 2 3 1 3 5 0 0 2 0 2 0 5 2 1 2 1 3 3 4 2 5 0 2 2 3 3 1 3 4 1 1 2 2 3 3 4 1 1 1 1 1
输出#1
2 8 4 3
说明/提示
Illustration for the first test dataset. In it, you can remove the edge between vertices 1 and 2. Then the bitwise XOR in the component consisting of vertices 2 and 5 is a2⊕a5=2⊕3=1. The bitwise XOR in the component with vertices 1, 3, and 4 is a1⊕a3⊕a4=0⊕2⊕3=1. The second beautiful set is the one consisting of the edge connecting vertices 1 and 3.

In the third test dataset, the beautiful sets will be (an edge is denoted by the pair of vertices it connects) [(1,2)],[(1,3)],[(2,5)],[(3,4)]. Note that the first and third samples differ only in the set b.
In the fourth test dataset, the beautiful sets will be [(1,2)],[(3,4)],[(1,2),(2,3),(3,4)].
第一个测试数据集的示意图。在此图中,你可以删除顶点 1 和 2 之间的边。此时,由顶点 2 和 5 构成的连通分量的按位异或值为 a2⊕a5=2⊕3=1;由顶点 1、3 和 4 构成的连通分量的按位异或值为 a1⊕a3⊕a4=0⊕2⊕3=1。第二个优美的集合是由连接顶点 1 和 3 的边构成的集合。

在第三个测试数据集中,优美的集合为(边用其所连接的两个顶点对表示):[(1,2)],[(1,3)],[(2,5)],[(3,4)]。注意,第一个和第三个样例仅在集合 b 上不同。
在第四个测试数据集中,优美的集合为:[(1,2)],[(3,4)],[(1,2),(2,3),(3,4)]。
输入解题思路,AI测评打分。不知道怎么写?