atcoder#AGC052F. [AGC052F] Tree Vertices XOR
[AGC052F] Tree Vertices XOR
Score : points
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 .
4
1 2
2 3
3 4
10
We can get the following configurations ( means vertices have written on them): , , , , , , , , , .
5
1 2
1 3
1 4
1 5
24
6
1 3
2 3
3 4
4 5
4 6
40
9
1 2
2 3
1 4
4 5
1 6
6 7
7 8
8 9
255