Tree XOR Sum

0

0 votes
Problem

You are given a tree (undirected) with N nodes. Each node has a value Ai (1iN) associated with it.

You can delete a subset (including none) of the edges from this tree such that the following conditions hold:

  1. There are no odd-sized components in the resulting graph.
  2. Define X as the sum of XOR’s of each component. The value of X should be maximum.

Find the value of X modulo 109+7.

Note: XOR of a component is defined as the XOR of the values associated with all the nodes in that component.

Input

  • The first line contains an integer N denoting the number of nodes in the tree.
  • Next line contains N space-separated integers Ai denoting the value associated of each node, as given in the problem statement.
  • Next N1 lines contain two space-separated integers u and v denoting an edge between nodes u and v.

Constraints

  • 1N5105
  • 0Ai109
  • N is even.

Output

  • Output the value of X modulo 109+7 as stated in the problem statement.
Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

Remove the edge between 2 and 3. This results in 2 components, each having xor sum as 3.

Editor Image

?