atcoder#ARC142D. [ARC142D] Deterministic Placing
[ARC142D] Deterministic Placing
Score : points
Problem Statement
We have a tree with vertices, numbered . For each , the -th edge connects Vertex and Vertex . An operation on this tree when at most one piece is put on each vertex is defined as follows.
- Simultaneously move every piece to one of the vertices adjacent to the one occupied by the piece.
An operation is said to be good when the conditions below are satisfied.
- Each edge is traversed by at most one piece.
- Each vertex will be occupied by at most one piece after the operation.
Takahashi will put a piece on one or more vertices of his choice. Among the ways to put pieces, find the number of ones that satisfy the condition below, modulo .
- For every non-negative integer , the following holds.- It is possible to perform a good operation times.
- Let be the set of vertices occupied by pieces just after good operations. Then, is unique.
- It is possible to perform a good operation times.
- Let be the set of vertices occupied by pieces just after good operations. Then, is unique.
Constraints
- The given graph is a tree.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
3
1 2
1 3
2
Here are the two ways to satisfy the condition.
- Put a piece on Vertex and Vertex .
- Put a piece on Vertex and Vertex .
Note that he must put a piece on at least one vertex.
7
1 2
1 3
2 4
2 5
3 6
3 7
0
There might be no way to satisfy the condition.
19
9 14
2 13
1 3
17 19
13 18
12 19
4 5
2 10
4 9
8 11
3 15
6 8
8 10
6 19
9 13
11 15
7 17
16 17
100