結果

問題 No.827 総神童数
ユーザー sho_00sho_00
提出日時 2020-04-09 11:53:28
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 959 bytes
コンパイル時間 152 ms
コンパイル使用メモリ 11,100 KB
実行使用メモリ 52,484 KB
最終ジャッジ日時 2023-09-30 05:10:02
合計ジャッジ時間 35,940 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,748 KB
testcase_01 AC 19 ms
8,860 KB
testcase_02 AC 19 ms
8,696 KB
testcase_03 AC 19 ms
8,824 KB
testcase_04 AC 20 ms
8,736 KB
testcase_05 AC 19 ms
8,692 KB
testcase_06 AC 19 ms
8,692 KB
testcase_07 AC 19 ms
8,780 KB
testcase_08 AC 19 ms
8,776 KB
testcase_09 TLE -
testcase_10 AC 633 ms
24,200 KB
testcase_11 AC 41 ms
9,456 KB
testcase_12 AC 254 ms
15,532 KB
testcase_13 AC 1,653 ms
43,660 KB
testcase_14 AC 64 ms
10,184 KB
testcase_15 AC 573 ms
22,900 KB
testcase_16 AC 1,661 ms
43,988 KB
testcase_17 TLE -
testcase_18 AC 764 ms
26,976 KB
testcase_19 TLE -
testcase_20 AC 1,387 ms
36,268 KB
testcase_21 AC 959 ms
28,844 KB
testcase_22 AC 1,556 ms
40,208 KB
testcase_23 AC 26 ms
8,868 KB
testcase_24 AC 1,728 ms
41,804 KB
testcase_25 AC 1,274 ms
34,032 KB
testcase_26 AC 1,736 ms
42,084 KB
testcase_27 AC 1,065 ms
31,040 KB
testcase_28 AC 1,043 ms
30,632 KB
testcase_29 AC 823 ms
26,296 KB
testcase_30 AC 211 ms
14,188 KB
testcase_31 AC 610 ms
22,628 KB
testcase_32 AC 576 ms
22,140 KB
testcase_33 AC 1,948 ms
45,212 KB
testcase_34 AC 1,760 ms
42,844 KB
testcase_35 AC 620 ms
22,756 KB
testcase_36 AC 934 ms
28,504 KB
testcase_37 AC 1,265 ms
33,816 KB
testcase_38 AC 1,912 ms
45,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0