結果

問題 No.827 総神童数
ユーザー AEnAEn
提出日時 2022-11-20 23:20:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,358 ms / 2,000 ms
コード長 784 bytes
コンパイル時間 181 ms
コンパイル使用メモリ 81,672 KB
実行使用メモリ 334,232 KB
最終ジャッジ日時 2023-10-21 18:35:45
合計ジャッジ時間 22,001 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,508 KB
testcase_01 AC 38 ms
53,508 KB
testcase_02 AC 38 ms
53,508 KB
testcase_03 AC 38 ms
53,508 KB
testcase_04 AC 38 ms
53,508 KB
testcase_05 AC 38 ms
53,508 KB
testcase_06 AC 38 ms
53,508 KB
testcase_07 AC 37 ms
53,508 KB
testcase_08 AC 38 ms
53,508 KB
testcase_09 AC 1,358 ms
334,232 KB
testcase_10 AC 515 ms
146,708 KB
testcase_11 AC 98 ms
78,348 KB
testcase_12 AC 242 ms
107,348 KB
testcase_13 AC 1,036 ms
279,332 KB
testcase_14 AC 118 ms
82,344 KB
testcase_15 AC 533 ms
143,888 KB
testcase_16 AC 1,140 ms
231,092 KB
testcase_17 AC 1,329 ms
277,160 KB
testcase_18 AC 658 ms
166,976 KB
testcase_19 AC 1,062 ms
103,892 KB
testcase_20 AC 643 ms
97,140 KB
testcase_21 AC 481 ms
91,532 KB
testcase_22 AC 696 ms
98,180 KB
testcase_23 AC 86 ms
76,624 KB
testcase_24 AC 770 ms
100,352 KB
testcase_25 AC 595 ms
95,476 KB
testcase_26 AC 767 ms
100,476 KB
testcase_27 AC 524 ms
93,220 KB
testcase_28 AC 519 ms
92,960 KB
testcase_29 AC 422 ms
89,612 KB
testcase_30 AC 181 ms
80,360 KB
testcase_31 AC 350 ms
86,724 KB
testcase_32 AC 336 ms
86,648 KB
testcase_33 AC 829 ms
102,864 KB
testcase_34 AC 774 ms
100,620 KB
testcase_35 AC 441 ms
86,976 KB
testcase_36 AC 467 ms
91,188 KB
testcase_37 AC 594 ms
95,480 KB
testcase_38 AC 879 ms
102,124 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0