結果

問題 No.827 総神童数
ユーザー sho_00sho_00
提出日時 2020-04-09 11:54:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 938 ms / 2,000 ms
コード長 959 bytes
コンパイル時間 2,136 ms
コンパイル使用メモリ 86,804 KB
実行使用メモリ 117,180 KB
最終ジャッジ日時 2023-09-29 17:30:19
合計ジャッジ時間 22,531 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
71,660 KB
testcase_01 AC 95 ms
71,860 KB
testcase_02 AC 96 ms
71,876 KB
testcase_03 AC 95 ms
71,812 KB
testcase_04 AC 94 ms
71,572 KB
testcase_05 AC 96 ms
71,716 KB
testcase_06 AC 95 ms
71,700 KB
testcase_07 AC 97 ms
71,272 KB
testcase_08 AC 97 ms
71,564 KB
testcase_09 AC 879 ms
117,180 KB
testcase_10 AC 328 ms
88,848 KB
testcase_11 AC 207 ms
79,968 KB
testcase_12 AC 230 ms
82,652 KB
testcase_13 AC 673 ms
106,404 KB
testcase_14 AC 171 ms
79,860 KB
testcase_15 AC 342 ms
88,764 KB
testcase_16 AC 678 ms
107,008 KB
testcase_17 AC 852 ms
115,388 KB
testcase_18 AC 417 ms
92,000 KB
testcase_19 AC 938 ms
116,636 KB
testcase_20 AC 673 ms
102,920 KB
testcase_21 AC 525 ms
95,852 KB
testcase_22 AC 729 ms
106,552 KB
testcase_23 AC 146 ms
78,496 KB
testcase_24 AC 834 ms
111,768 KB
testcase_25 AC 614 ms
101,620 KB
testcase_26 AC 825 ms
111,180 KB
testcase_27 AC 557 ms
97,756 KB
testcase_28 AC 563 ms
98,428 KB
testcase_29 AC 475 ms
93,968 KB
testcase_30 AC 253 ms
83,892 KB
testcase_31 AC 388 ms
90,532 KB
testcase_32 AC 380 ms
90,928 KB
testcase_33 AC 884 ms
115,920 KB
testcase_34 AC 852 ms
111,948 KB
testcase_35 AC 408 ms
92,144 KB
testcase_36 AC 494 ms
95,564 KB
testcase_37 AC 620 ms
101,544 KB
testcase_38 AC 874 ms
114,452 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