結果

問題 No.827 総神童数
ユーザー hedwig100hedwig100
提出日時 2020-04-21 22:00:17
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 872 ms / 2,000 ms
コード長 815 bytes
コンパイル時間 288 ms
コンパイル使用メモリ 86,692 KB
実行使用メモリ 113,552 KB
最終ジャッジ日時 2023-07-30 17:31:14
合計ジャッジ時間 19,541 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
71,424 KB
testcase_01 AC 92 ms
71,428 KB
testcase_02 AC 92 ms
71,608 KB
testcase_03 AC 91 ms
71,428 KB
testcase_04 AC 92 ms
71,308 KB
testcase_05 AC 91 ms
71,320 KB
testcase_06 AC 90 ms
71,428 KB
testcase_07 AC 90 ms
71,552 KB
testcase_08 AC 93 ms
71,308 KB
testcase_09 AC 802 ms
112,944 KB
testcase_10 AC 297 ms
87,304 KB
testcase_11 AC 133 ms
77,580 KB
testcase_12 AC 193 ms
81,912 KB
testcase_13 AC 623 ms
103,576 KB
testcase_14 AC 136 ms
77,840 KB
testcase_15 AC 276 ms
86,256 KB
testcase_16 AC 644 ms
104,600 KB
testcase_17 AC 760 ms
111,544 KB
testcase_18 AC 335 ms
89,176 KB
testcase_19 AC 872 ms
113,552 KB
testcase_20 AC 604 ms
100,452 KB
testcase_21 AC 451 ms
94,216 KB
testcase_22 AC 699 ms
103,932 KB
testcase_23 AC 131 ms
77,776 KB
testcase_24 AC 794 ms
107,984 KB
testcase_25 AC 588 ms
99,064 KB
testcase_26 AC 810 ms
108,240 KB
testcase_27 AC 515 ms
95,332 KB
testcase_28 AC 500 ms
95,268 KB
testcase_29 AC 414 ms
91,852 KB
testcase_30 AC 205 ms
81,852 KB
testcase_31 AC 333 ms
88,020 KB
testcase_32 AC 324 ms
86,904 KB
testcase_33 AC 860 ms
111,988 KB
testcase_34 AC 813 ms
108,184 KB
testcase_35 AC 333 ms
87,852 KB
testcase_36 AC 461 ms
93,496 KB
testcase_37 AC 578 ms
98,428 KB
testcase_38 AC 842 ms
111,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

INF = 10 ** 9
MOD = 10 **9 + 7
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from  collections import deque
from math import factorial

def main():
    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)
    
    stack = [(0,-1)]
    ancestors = [0] * n
    while stack:
        v,p = stack.pop()
        for e in G[v]:
            if e == p:
                continue
            ancestors[e] = ancestors[v] + 1
            stack.append((e,v))
    
    fact = factorial(n)%MOD
    
    ans = 0
    for d in ancestors:
        ans += fact * pow(d + 1,MOD - 2,MOD) % MOD
        ans %= MOD
    
    print(ans)
  
if __name__=='__main__':
    main()
0