atcoder#MUJINPC2017D. Oriented Tree
Oriented Tree
Score : points
Problem Statement
There is a tree with vertices, numbered through . For each , the -th edge connects vertices and .
Snuke is constructing a directed graph by arbitrarily assigning direction to each edge in . (There are different ways to construct .)
For a fixed , we will define for each , as follows:
- (The number of edges that must be traversed against the assigned direction when traveling from vertex to vertex )
In particular, for each . Also note that, in general, .
We will further define as the following:
Snuke is constructing so that will be the minimum possible value. How many different ways are there to construct so that will be the minimum possible value, modulo ?
Constraints
- The given graph is a tree.
Input
The input is given from Standard Input in the following format:
Output
Print the number of the different ways to construct so that will be the minimum possible value, modulo .
4
1 2
1 3
1 4
2
The minimum possible value for is . There are two ways to construct to achieve this value, as shown in the following figure:
4
1 2
2 3
3 4
6
The minimum possible value for is . There are six ways to construct to achieve this value, as shown in the following figure:
6
1 2
1 3
1 4
2 5
2 6
14
10
2 4
2 5
8 3
10 7
1 6
2 8
9 5
8 6
10 6
102