#arc130d. [arc130_d]Zigzag Tree
[arc130_d]Zigzag Tree
Problem Statement
Given is a tree with vertices. The vertices are numbered to , and the -th edge connects Vertices and .
Find the number of sequences of positive integers that satisfy the conditions below, modulo .
- if .
- For , if Vertices and are adjacent, and Vertices and are also adjacent, or holds.
Constraints
- The given graph is a tree.
Input
Input is given from Standard Input in the following format:
Output
Print the answers.
Sample Input 1
3
1 2
2 3
Sample Output 1
4
The sequences satisfying the conditions are:
Sample Input 2
4
1 2
1 3
1 4
Sample Output 2
12
Sample Input 3
6
1 2
2 3
3 4
4 5
5 6
Sample Output 3
122
Sample Input 4
9
8 5
9 8
1 9
2 5
6 1
7 6
3 8
4 1
Sample Output 4
19080