結果

問題 No.827 総神童数
ユーザー H3PO4H3PO4
提出日時 2021-02-17 09:39:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 625 ms / 2,000 ms
コード長 759 bytes
コンパイル時間 501 ms
コンパイル使用メモリ 87,204 KB
実行使用メモリ 121,700 KB
最終ジャッジ日時 2023-10-11 21:13:39
合計ジャッジ時間 17,132 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 102 ms
78,252 KB
testcase_01 AC 104 ms
78,292 KB
testcase_02 AC 110 ms
78,200 KB
testcase_03 AC 109 ms
78,224 KB
testcase_04 AC 104 ms
78,372 KB
testcase_05 AC 103 ms
78,276 KB
testcase_06 AC 107 ms
78,264 KB
testcase_07 AC 107 ms
78,288 KB
testcase_08 AC 113 ms
78,368 KB
testcase_09 AC 520 ms
116,212 KB
testcase_10 AC 260 ms
95,252 KB
testcase_11 AC 129 ms
79,272 KB
testcase_12 AC 186 ms
86,388 KB
testcase_13 AC 433 ms
107,776 KB
testcase_14 AC 136 ms
79,032 KB
testcase_15 AC 229 ms
89,240 KB
testcase_16 AC 425 ms
105,980 KB
testcase_17 AC 517 ms
119,684 KB
testcase_18 AC 275 ms
92,084 KB
testcase_19 AC 625 ms
121,700 KB
testcase_20 AC 471 ms
112,556 KB
testcase_21 AC 375 ms
103,368 KB
testcase_22 AC 509 ms
113,544 KB
testcase_23 AC 132 ms
79,256 KB
testcase_24 AC 538 ms
113,244 KB
testcase_25 AC 427 ms
108,584 KB
testcase_26 AC 541 ms
112,708 KB
testcase_27 AC 381 ms
101,192 KB
testcase_28 AC 388 ms
103,020 KB
testcase_29 AC 334 ms
99,880 KB
testcase_30 AC 199 ms
85,784 KB
testcase_31 AC 306 ms
96,140 KB
testcase_32 AC 299 ms
95,592 KB
testcase_33 AC 581 ms
119,580 KB
testcase_34 AC 564 ms
113,552 KB
testcase_35 AC 296 ms
95,768 KB
testcase_36 AC 357 ms
102,928 KB
testcase_37 AC 440 ms
109,856 KB
testcase_38 AC 563 ms
119,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import deque

input = sys.stdin.buffer.readline

MOD = 10 ** 9 + 7
MAX = 2 * 10 ** 5 + 10
modinv = lambda a, mod=MOD: pow(a, mod - 2, mod)
fac = [1] * MAX
for i in range(1, MAX):
    fac[i] = fac[i - 1] * i % MOD

N = int(input())
T = [[] for _ in range(N)]
UV = [tuple(int(x) - 1 for x in input().split()) for _ in range(N - 1)]
for u, v in UV:
    T[u].append(v)
    T[v].append(u)

# dfs
d = deque([0])
nonvisited = [True] * N
nonvisited[0] = False
height = [0] * N
while d:
    v = d.pop()
    h = height[v] + 1
    for x in T[v]:
        if nonvisited[x]:
            d.append(x)
            nonvisited[x] = False
            height[x] = h

ans = 0
for h in height:
    ans += fac[N] * modinv(h + 1)
    ans %= MOD
print(ans)
0