F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Tree Cutting

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/131072 K (Java/Others)
Total Submission(s): 3245    Accepted Submission(s): 1147


Problem Description
Byteasar has a tree $T$ with $n$ vertices conveniently labeled with $1,2,...,n$. Each vertex of the tree has an integer value $v_i$.

The value of a non-empty tree $T$ is equal to $v_1\oplus v_2\oplus ...\oplus v_n$, where $\oplus$ denotes bitwise-xor.

Now for every integer $k$ from $[0,m)$, please calculate the number of non-empty subtree of $T$ which value are equal to $k$.

A subtree of $T$ is a subgraph of $T$ that is also a tree.
 

Input
The first line of the input contains an integer $T(1\leq T\leq10)$, denoting the number of test cases.

In each test case, the first line of the input contains two integers $n(n\leq 1000)$ and $m(1\leq m\leq 2^{10})$, denoting the size of the tree $T$ and the upper-bound of $v$.

The second line of the input contains $n$ integers $v_1,v_2,v_3,...,v_n(0\leq v_i < m)$, denoting the value of each node.

Each of the following $n-1$ lines contains two integers $a_i,b_i$, denoting an edge between vertices $a_i$ and $b_i(1\leq a_i,b_i\leq n)$.

It is guaranteed that $m$ can be represent as $2^k$, where $k$ is a non-negative integer.
 

Output
For each test case, print a line with $m$ integers, the $i$-th number denotes the number of non-empty subtree of $T$ which value are equal to $i$.

The answer is huge, so please module $10^9+7$.
 

Sample Input
2 4 4 2 0 1 3 1 2 1 3 1 4 4 4 0 1 3 1 1 2 1 3 1 4
 

Sample Output
3 3 2 3 2 4 2 3
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-18 17:36:10, Gzip enabled