atcoder#ARC130D. [ARC130D] Zigzag Tree
[ARC130D] Zigzag Tree
Score : points
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.
3
1 2
2 3
4
The sequences satisfying the conditions are:
4
1 2
1 3
1 4
12
6
1 2
2 3
3 4
4 5
5 6
122
9
8 5
9 8
1 9
2 5
6 1
7 6
3 8
4 1
19080