#AGC050F. [AGC050F] NAND Tree

[AGC050F] NAND Tree

Score : 20002000 points

Problem Statement

There is a tree whose vertices are labelled with either 00 or 11. The tree has NN vertices numbered 11 through NN. For each ii, there is an edge connecting Vertex aia_i and Vertex bib_i. The label of Vertex ii is cic_i.

Snuke wants to repeat performing the following operation on the tree:

  • Choose an edge, contract it, and label the new vertex with the NAND of the labels of two old vertices.

After performing N1N - 1 operations, the tree ends up with a single vertex. Among (N1)!(N-1)! ways to do so, how many will result in a vertex labelled with 11? Compute the answer modulo 2.

Notes

  • NAND operation is defined as follows: $NAND(0, 0) = NAND(0, 1) = NAND(1, 0) = 1, NAND(1, 1) = 0$.
  • When we contract an edge between Vertex ss and Vertex tt, we remove the edge, and simultaneously merge the two vertices. There is an edge between the merged vertex and Vertex uu in the new tree iff there is an edge between ss and uu, or an edge between tt and uu, in the old tree.

Constraints

  • 2N3002 \leq N \leq 300
  • 1ai<biN1 \leq a_i < b_i \leq N
  • The input represents a valid tree.
  • 0ci10 \leq c_i \leq 1
  • All values in the input are integers.

Input

Input is given from Standard Input in the following format:

NN

a1a_1 b1b_1

::

aN1a_{N-1} bN1b_{N-1}

c1c_1 c2c_2 \cdots cNc_N

Output

Print the answer.

4
1 2
2 3
2 4
0 1 1 0
0

It turns out that in 44 of all 66 ways the final label will be 11, so the answer is 4 mod 2=04 \ mod \ 2 = 0.

4
1 2
2 3
3 4
1 1 0 1
1
20
3 15
1 12
10 16
3 19
5 20
1 9
6 13
14 19
2 4
8 11
12 16
6 20
2 17
16 18
17 19
7 10
16 20
2 20
8 20
1 0 0 1 1 0 1 1 1 0 0 1 0 1 0 1 1 1 0 0
0