Bad XOR 2 (Hard)

Limits: 4s, 512 MB

So after successfully becoming many people’s nightmare, XOR has struck again, this time to haunt you on a tree!!! You are given a tree with N vertices. The vertices are numbered from 1 to N. Each vertices holds a non-negative integer value. You are also given a set of non-negative integers, these integers are bad. The values of each vetices of the tree and the set are less than 501.You need to find out the number of non-empty subtrees of the given tree such that the XOR of all the values of the vertices of the subtree doesn’t exist in the given set.

This is a companion discussion topic for the original entry at