No.1302 Random Tree Score
タグ : / 解いたユーザー数 81
作問者 :
nok0
/ テスター :
tpyneriver
Kite_kuma
Problem Statement
For a tree with $N$ vertices numbered from $1$ to $N$, define the score of the tree as
score $:=\displaystyle \prod_{i=1}^N$ (degree of vertex $i$)
.
There are $N ^ {N - 2}$ trees with $N$ vertices numbered from $1$ to $N$. Find the average of the score over these trees and print it $\mbox{mod } 998244353$.
More precisely, under the constraints of this problem, it can be proved that the average is a rational number, that is, it can be expressed as an irreducible fraction $\frac{P}{Q}$, and that an integer $R$ satisfying $R×Q≡P(\mbox{mod } 998244353),\ 0 \le R< 998244353$ is uniquely determined. Print this $R$.
Input
$N$
Output
Print the average of the score $\mbox{mod } 998244353$.
Sample
Sample 1
Input
3
Output
2
There are $3$ trees with $3$ vertices. In every tree, the vertex degrees are {$2, 1, 1$}, so the score is $2 × 1 × 1 = 2$. Therefore, the average is also $2$.
Sample 2
Input
4
Output
249561092
There are $16$ trees with $4$ vertices. Among them, $12$ trees have the $4$ vertex degrees {$2, 2, 1, 1$}, and the remaining $4$ trees have {$3, 1, 1, 1$}, so the average of the score is $\frac{4 × 12 + 3 × 4}{16} = \frac{15}{4}$. Since $249561092×4≡15(\mbox{mod } 998244353) $, print $249561092$.
Sample 3
Input
27182
Output
877912165
Print the answer $\mbox{mod } 998244353$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。