結果
| 問題 |
No.827 総神童数
|
| コンテスト | |
| ユーザー |
AEn
|
| 提出日時 | 2022-11-20 23:20:55 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,322 ms / 2,000 ms |
| コード長 | 784 bytes |
| コンパイル時間 | 200 ms |
| コンパイル使用メモリ | 82,168 KB |
| 実行使用メモリ | 334,124 KB |
| 最終ジャッジ日時 | 2024-09-21 19:55:55 |
| 合計ジャッジ時間 | 20,314 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 36 |
ソースコード
import sys
sys.setrecursionlimit(10**8)
import pypyjit
pypyjit.set_param("max_unroll_recursion=-1")
mod = 10**9+7
N = int(input())
G = [list() for _ in range(N)]
for i in range(N-1):
u, v = map(int,input().split())
u-=1;v-=1
G[u].append(v)
G[v].append(u)
fac = [0]*(N+1)
inv = [0]*(N+1)
fac[0]=1;inv[0]=1
for i in range(1,N+1):
fac[i] = (fac[i-1]*i)%mod
inv[i] = (inv[i-1]*pow(i,mod-2,mod))%mod
def ncr(r):
return (fac[N]*inv[r]*inv[N-r])%mod
res = (N*fac[N-1])%mod
depth = [0]*N
depth[0] = 1
def dfs(v,p):
for nex in G[v]:
if nex==p:
continue
depth[nex] = depth[v]+1
global res
res += (ncr(depth[nex])*fac[depth[nex]-1]*fac[N-depth[nex]])%mod
res %= mod
dfs(nex,v)
dfs(0,-1)
print(res)
AEn