atcoder#ARC087D. [ARC087F] Squirrel Migration
[ARC087F] Squirrel Migration
Score : points
Problem Statement
There is a tree with vertices. The vertices are numbered through . The -th edge () connects Vertex and . For vertices and (), we will define the distance between and as "the number of edges contained in the path -".
A squirrel lives in each vertex of the tree. They are planning to move, as follows. First, they will freely choose a permutation of , . Then, for each , the squirrel that lived in Vertex will move to Vertex .
Since they like long travels, they have decided to maximize the total distance they traveled during the process. That is, they will choose so that will be maximized. How many such ways are there to choose , modulo ?
Constraints
- The input graph is a tree.
Input
Input is given from Standard Input in the following format:
Output
Print the number of the ways to choose so that the condition is satisfied, modulo .
3
1 2
2 3
3
The maximum possible distance traveled by squirrels is . There are three choices of that achieve it, as follows:
4
1 2
1 3
1 4
11
The maximum possible distance traveled by squirrels is . For example, achieves it.
6
1 2
1 3
1 4
2 5
2 6
36
7
1 2
6 3
4 5
1 7
1 5
2 3
396