No.827 総神童数
タグ : / 解いたユーザー数 137
作問者 :
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Show the original
Problem Statement
Aoki has obtained a rooted tree $T$ consisting of vertices $1,2,...,N$. The root of $T$ is vertex $1$.
Aoki is considering writing the values $1,2,...,N$ on the vertices of the rooted tree $T$, without duplicates.
That is, letting $c_i$ be the value written on vertex $i$, the sequence $\{c_i\}$ must be a permutation of $\{1,2,...,N\}$.
Aoki has decided to call vertex $i$ a prodigy when "vertex $i$ has a value written on it that is greater than the values of all ancestors of vertex $i$ (excluding itself)". The root is always a prodigy.
He also defined the prodigy count as the number of vertices among the $N$ vertices that are prodigies.
For example, for the assignment of values shown in the figure below, the yellow vertices are prodigies, and the prodigy count is 4.
Here, the vertex with the value $6$ written on it is a prodigy, because the values $\{3,1\}$ are written on its ancestors, which contain only values less than $6$.
The vertex with the value $4$ written on it is not a prodigy, because the values $\{3,7\}$ are written on its ancestors, which contain a value greater than $4$.
Aoki became curious about how excellent the rooted tree $T$ is, and asked what the total of the prodigy counts would be if all $N!$ ways of writing the values were tried.
Your task is to compute this answer on Aoki's behalf.
Since this value can be very large, report it modulo $10^9+7$.
Input
$N$
$u_1\ v_1$
$u_2\ v_2$
$\vdots$
$u_{N-1}\ v_{N-1}$
The first line contains the number of vertices $N$ of the tree.
Each of the 2nd through $N$-th lines contains space-separated integers $u, v$ representing the endpoints of an edge of the tree $T$. This means that vertices $u, v$ are connected bidirectionally.
Constraints
- $1 \le N \le 2\times 10^5$
- $1 \le u_i,v_i \le N$
- The input graph is a tree with $N$ vertices.
- All input values are integers.
Output
Output on one line the sum of the prodigy counts over all $N!$ ways of writing values on $T$, modulo $10^9+7$.
Print a newline at the end.
Sample
Sample 1
Input
2 1 2
Output
3
There are the following 2 ways of writing the values, and the yellow vertices are prodigies.
On the right, the vertex with 1 written on it is not a prodigy, because its parent's value is 2, which is greater than its own value.
Sample 2
Input
3 1 2 2 3
Output
11
There are the following 6 ways of writing the values, and the yellow vertices are prodigies.
Sample 3
Input
20 2 15 6 5 12 1 7 9 17 2 15 5 2 4 17 16 12 2 8 17 17 19 18 11 20 8 20 3 13 9 11 10 11 20 14 8 11 7
Output
820010006
Note that the answer is taken modulo $10^9+7$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。