結果

問題 No.827 総神童数
ユーザー convexineqconvexineq
提出日時 2021-04-03 13:11:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 353 ms / 2,000 ms
コード長 962 bytes
コンパイル時間 953 ms
コンパイル使用メモリ 86,984 KB
実行使用メモリ 109,956 KB
最終ジャッジ日時 2023-08-26 03:43:27
合計ジャッジ時間 10,240 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
82,732 KB
testcase_01 AC 80 ms
82,964 KB
testcase_02 AC 80 ms
82,880 KB
testcase_03 AC 78 ms
83,168 KB
testcase_04 AC 80 ms
83,152 KB
testcase_05 AC 81 ms
82,960 KB
testcase_06 AC 79 ms
82,884 KB
testcase_07 AC 79 ms
82,964 KB
testcase_08 AC 76 ms
82,728 KB
testcase_09 AC 286 ms
109,956 KB
testcase_10 AC 158 ms
93,276 KB
testcase_11 AC 110 ms
84,616 KB
testcase_12 AC 127 ms
86,608 KB
testcase_13 AC 276 ms
105,128 KB
testcase_14 AC 123 ms
85,316 KB
testcase_15 AC 151 ms
92,368 KB
testcase_16 AC 240 ms
105,532 KB
testcase_17 AC 276 ms
108,984 KB
testcase_18 AC 169 ms
93,996 KB
testcase_19 AC 353 ms
109,920 KB
testcase_20 AC 268 ms
102,724 KB
testcase_21 AC 218 ms
97,472 KB
testcase_22 AC 275 ms
105,552 KB
testcase_23 AC 106 ms
84,888 KB
testcase_24 AC 322 ms
106,552 KB
testcase_25 AC 247 ms
101,008 KB
testcase_26 AC 320 ms
106,560 KB
testcase_27 AC 228 ms
98,168 KB
testcase_28 AC 226 ms
98,220 KB
testcase_29 AC 205 ms
96,596 KB
testcase_30 AC 137 ms
88,208 KB
testcase_31 AC 172 ms
93,336 KB
testcase_32 AC 178 ms
93,132 KB
testcase_33 AC 344 ms
109,420 KB
testcase_34 AC 320 ms
106,632 KB
testcase_35 AC 187 ms
93,452 KB
testcase_36 AC 219 ms
97,340 KB
testcase_37 AC 258 ms
101,128 KB
testcase_38 AC 314 ms
109,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

SIZE=3*10**5+1; MOD=10**9+7 #998244353 #ここを変更する

inv = [0]*SIZE  # inv[j] = j^{-1} mod MOD
fac = [0]*SIZE  # fac[j] = j! mod MOD
finv = [0]*SIZE # finv[j] = (j!)^{-1} mod MOD
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
for i in range(2,SIZE):
    fac[i] = fac[i-1]*i%MOD
finv[-1] = pow(fac[-1],MOD-2,MOD)
for i in range(SIZE-1,0,-1):
    finv[i-1] = finv[i]*i%MOD
    inv[i] = finv[i]*fac[i-1]%MOD

def choose(n,r): # nCk mod MOD の計算
    if 0 <= r <= n:
        return (fac[n]*finv[r]%MOD)*finv[n-r]%MOD
    else:
        return 0


n = int(input())
g = [[] for _ in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)
 
depth = [1]*n
st = [0]
parent = [-1]*n
while st:
    v = st.pop()
    for c in g[v]:
        if c != parent[v]:
            st.append(c)
            parent[c] = v
            depth[c] = depth[v] + 1

ans = 0
for d in depth:
    ans += inv[d]
print(ans*fac[n]%MOD)
0