結果

問題 No.827 総神童数
ユーザー tktk_snsntktk_snsn
提出日時 2021-01-07 21:13:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 413 ms / 2,000 ms
コード長 659 bytes
コンパイル時間 1,854 ms
コンパイル使用メモリ 82,088 KB
実行使用メモリ 127,164 KB
最終ジャッジ日時 2024-04-26 13:49:57
合計ジャッジ時間 9,686 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
54,336 KB
testcase_01 AC 40 ms
54,860 KB
testcase_02 AC 40 ms
54,364 KB
testcase_03 AC 40 ms
54,944 KB
testcase_04 AC 39 ms
54,224 KB
testcase_05 AC 39 ms
54,772 KB
testcase_06 AC 40 ms
54,540 KB
testcase_07 AC 39 ms
55,132 KB
testcase_08 AC 40 ms
54,072 KB
testcase_09 AC 413 ms
127,164 KB
testcase_10 AC 151 ms
89,084 KB
testcase_11 AC 66 ms
70,848 KB
testcase_12 AC 118 ms
83,500 KB
testcase_13 AC 330 ms
111,708 KB
testcase_14 AC 68 ms
71,920 KB
testcase_15 AC 161 ms
91,088 KB
testcase_16 AC 270 ms
108,380 KB
testcase_17 AC 335 ms
116,500 KB
testcase_18 AC 200 ms
97,484 KB
testcase_19 AC 318 ms
98,396 KB
testcase_20 AC 198 ms
91,092 KB
testcase_21 AC 157 ms
88,844 KB
testcase_22 AC 226 ms
94,976 KB
testcase_23 AC 56 ms
66,720 KB
testcase_24 AC 261 ms
96,968 KB
testcase_25 AC 186 ms
90,328 KB
testcase_26 AC 264 ms
97,356 KB
testcase_27 AC 190 ms
89,300 KB
testcase_28 AC 167 ms
89,104 KB
testcase_29 AC 158 ms
87,564 KB
testcase_30 AC 90 ms
79,504 KB
testcase_31 AC 112 ms
82,428 KB
testcase_32 AC 121 ms
82,304 KB
testcase_33 AC 266 ms
98,152 KB
testcase_34 AC 250 ms
97,116 KB
testcase_35 AC 114 ms
82,588 KB
testcase_36 AC 143 ms
88,588 KB
testcase_37 AC 178 ms
90,512 KB
testcase_38 AC 256 ms
97,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
mod = 10 ** 9 + 7

N = int(input())
G = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)

dist = [-1] * N
que = [0]
dist[0] = 1
while que:
    s = que.pop()
    for t in G[s]:
        if dist[t] == -1:
            dist[t] = dist[s] + 1
            que.append(t)

fact = 1
for i in range(1, N + 1):
    fact = fact * i % mod

ans = 0
for d, cnt in Counter(dist).items():
    p = pow(d, mod - 2, mod) * fact % mod
    ans += p * cnt
    ans %= mod

print(ans)
0