結果

問題 No.827 総神童数
ユーザー hedwig100
提出日時 2020-04-21 22:02:13
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 761 bytes
コンパイル時間 219 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 58,832 KB
最終ジャッジ日時 2024-10-09 12:46:04
合計ジャッジ時間 39,562 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other WA * 31 TLE * 5
権限があれば一括ダウンロードができます

ソースコード

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 = sum([fact * pow(d,MOD - 2,MOD) for d in ancestors])
    print(ans)
  
if __name__=='__main__':
    main()
0