Your friend has come to visit the RUET campus. As the Mango season goes on , he/she said “Mama Aam Khawa!”. As Manik Bhai leased those Mango Trees, he will not give you guys Mangoes for free rather he gave you a problem as he knew you are a great problem solver. You and your friend want one mango for each but with Distinction. The Distinction means bitwise of the sweetness of mangoes must be positive (greater than zero). There will be multiple queries.
Given a Mango Tree rooted at node . Each node represents a Mango with sweetness . Manik bhai will only let you choose mangoes from a subtree. So, in each query, Manik bhai will give you a node and you just need to find in the subtree rooted at , how many ways you can take two mangoes such that they have Distinction.
A subtree of a tree is a tree that consists of a node in the tree
and all of this node's descendants. The tree can also be considered as a subtree of itself.
The first line of the input will have () and (), number of Mangoes in the Tree and number of queries respectively.
Then the next line contains N numbers in form (), the sweetness of the -th mango.
Next lines, each containing () and () as there is a branch between node and . It’s guaranteed that they will form a Tree.
The next line contains numbers, indicating , the root of the Subtree for each query.
For each query, print the answer of the Query. As the answer can be too large print modulo .
Input | Output |
---|---|
5 5 1 2 2 3 2 1 2 2 4 1 3 2 5 1 2 3 4 5 | 7 2 0 0 0 |