結果

問題 No.827 総神童数
ユーザー hedwig100
提出日時 2020-04-21 21:59:42
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 815 bytes
コンパイル時間 257 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 53,088 KB
最終ジャッジ日時 2024-10-09 12:41:41
合計ジャッジ時間 42,004 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29 TLE * 7
権限があれば一括ダウンロードができます

ソースコード

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