結果

問題 No.827 総神童数
ユーザー ntudantuda
提出日時 2022-12-11 14:13:42
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 506 bytes
コンパイル時間 224 ms
コンパイル使用メモリ 82,696 KB
実行使用メモリ 123,912 KB
最終ジャッジ日時 2024-04-23 11:23:45
合計ジャッジ時間 12,665 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
52,944 KB
testcase_01 AC 33 ms
53,144 KB
testcase_02 AC 34 ms
52,676 KB
testcase_03 AC 34 ms
53,832 KB
testcase_04 AC 35 ms
52,472 KB
testcase_05 AC 34 ms
53,892 KB
testcase_06 AC 34 ms
52,864 KB
testcase_07 AC 32 ms
52,608 KB
testcase_08 AC 32 ms
53,304 KB
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 AC 514 ms
120,592 KB
testcase_20 AC 407 ms
109,536 KB
testcase_21 AC 317 ms
100,684 KB
testcase_22 AC 445 ms
111,704 KB
testcase_23 AC 72 ms
75,368 KB
testcase_24 AC 449 ms
115,548 KB
testcase_25 AC 358 ms
106,784 KB
testcase_26 AC 472 ms
115,612 KB
testcase_27 AC 353 ms
103,180 KB
testcase_28 AC 329 ms
102,884 KB
testcase_29 AC 259 ms
97,684 KB
testcase_30 AC 141 ms
83,536 KB
testcase_31 AC 234 ms
93,432 KB
testcase_32 AC 221 ms
92,408 KB
testcase_33 AC 513 ms
119,000 KB
testcase_34 AC 472 ms
115,896 KB
testcase_35 AC 271 ms
93,184 KB
testcase_36 AC 305 ms
100,488 KB
testcase_37 AC 358 ms
106,460 KB
testcase_38 AC 496 ms
118,492 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 10 ** 9 + 7
N = int(input())
UV = [list(map(int, input().split())) for _ in range(N - 1)]
E = [[] for _ in range(N)]
factn = 1
for i in range(1, N + 1):
    factn *= i
    factn %= MOD

for u, v in UV:
    u -= 1
    v -= 1
    E[u].append(v)
    E[v].append(u)

def dfs(u, p, g):
    G[g] += 1
    for v in E[u]:
        if v != p:
            dfs(v, u, g + 1)

G = [0] * N
dfs(0, -1, 0)
ans = 0
for i, g in enumerate(G, start = 1):
    ans += factn * pow(i,MOD-2,MOD) * g
    ans %= MOD
print(ans)
0