#agc052f. [agc052_f]Tree Vertices XOR
[agc052_f]Tree Vertices XOR
Problem Statement
You are given a tree with vertices. The vertices are numbered from to , and the -th edge connects vertices and .
Initially, on each vertex of the tree is written number .
In one operation, you can do the following:
- Choose any vertex of the tree. Let be the XOR of the values written in the neighbors of . Then, if the number written on is , replace it by .
You can perform this operation any finite (maybe zero) number of times. How many configurations can you achieve? As this number can be large, output it modulo .
Two configurations are called different if there exists a vertex , such that the numbers written in in these configurations are different.
Constraints
- The input represents a valid tree.
Input
Input is given from Standard Input in the following format:
Output
Output the number of configurations you can get from the initial state, modulo .
Sample Input 1
4
1 2
2 3
3 4
Sample Output 1
10
We can get the following configurations ( means vertices have written on them): , , , , , , , , , .
Sample Input 2
5
1 2
1 3
1 4
1 5
Sample Output 2
24
Sample Input 3
6
1 3
2 3
3 4
4 5
4 6
Sample Output 3
40
Sample Input 4
9
1 2
2 3
1 4
4 5
1 6
6 7
7 8
8 9
Sample Output 4
255