#hitachi2020f. [hitachi2020_f]Preserve Diameter
[hitachi2020_f]Preserve Diameter
Problem Statement
We have a tree with vertices numbered to . The -th edge of connects Vertex and Vertex .
Consider adding zero or more edges in , and let be the graph resulted.
Find the number of graphs that satisfy the following conditions, modulo .
- does not contain self-loops or multiple edges.
- The diameters of and are equal.
- For every pair of vertices in that is not directly connected by an edge, the addition of an edge directly connecting them would reduce the diameter of the graph.
Constraints
- The given graph is a tree.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
6
1 6
2 1
5 2
3 4
2 3
Sample Output 1
3
For example, adding the edges in satisfies the conditions.
Sample Input 2
3
1 2
2 3
Sample Output 2
1
The only graph that satisfies the conditions is .
Sample Input 3
9
1 2
2 3
4 2
1 7
6 1
2 5
5 9
6 8
Sample Output 3
27
Sample Input 4
19
2 4
15 8
1 16
1 3
12 19
1 18
7 11
11 15
12 9
1 6
7 14
18 2
13 12
13 5
16 13
7 1
11 10
7 17
Sample Output 4
78732