結果
問題 | No.827 総神童数 |
ユーザー |
![]() |
提出日時 | 2020-04-09 11:54:37 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 901 ms / 2,000 ms |
コード長 | 959 bytes |
コンパイル時間 | 281 ms |
コンパイル使用メモリ | 82,324 KB |
実行使用メモリ | 114,048 KB |
最終ジャッジ日時 | 2024-07-22 11:31:38 |
合計ジャッジ時間 | 19,295 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
from collections import deque import math n=int(input()) E=[[] for _ in range(n)] for i in range(n-1): a,b=map(int,input().split()) a-=1 b-=1 E[a].append(b) E[b].append(a) depth=[0]*n seen=[0]*n seen[0]=1 stack=deque([0]) while stack: u=stack.pop() for v in E[u]: if seen[v]!=1: seen[v]=1 depth[v]=depth[u]+1 stack.append(v) mod=10**9+7 def sq(a, b, mod): # aのb乗を剰余 if b == 0: return 1 elif b % 2 == 0: return sq(a, b // 2, mod)**2 % mod else: return sq(a, b - 1, mod) * a % mod def egcd(a, b): if a == 0: return b, 0, 1 else: g, y, x = egcd(b % a, a) return g, x - (b // a) * y, y def modinv(a, m): g, x, y = egcd(a, m) if g != 1: raise Exception('modular inverse does not exist') else: return x % m v=math.factorial(n)%mod inv=0 for i in range(n): inv+=modinv(depth[i]+1,mod) ans=v*inv%mod print(ans)