結果
| 問題 |
No.827 総神童数
|
| コンテスト | |
| ユーザー |
sho_00
|
| 提出日時 | 2020-04-09 11:53:28 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 959 bytes |
| コンパイル時間 | 124 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 54,672 KB |
| 最終ジャッジ日時 | 2024-07-22 23:06:40 |
| 合計ジャッジ時間 | 39,483 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 TLE * 5 |
ソースコード
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)
sho_00