結果

問題 No.827 総神童数
ユーザー titiatitia
提出日時 2019-05-03 23:46:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 650 ms / 2,000 ms
コード長 774 bytes
コンパイル時間 290 ms
コンパイル使用メモリ 87,108 KB
実行使用メモリ 168,908 KB
最終ジャッジ日時 2023-08-30 07:02:31
合計ジャッジ時間 18,730 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 260 ms
104,888 KB
testcase_01 AC 266 ms
104,944 KB
testcase_02 AC 265 ms
105,080 KB
testcase_03 AC 261 ms
104,908 KB
testcase_04 AC 264 ms
105,084 KB
testcase_05 AC 258 ms
105,056 KB
testcase_06 AC 260 ms
104,884 KB
testcase_07 AC 259 ms
104,952 KB
testcase_08 AC 260 ms
105,016 KB
testcase_09 AC 650 ms
157,688 KB
testcase_10 AC 405 ms
133,452 KB
testcase_11 AC 292 ms
107,644 KB
testcase_12 AC 328 ms
117,188 KB
testcase_13 AC 551 ms
147,076 KB
testcase_14 AC 298 ms
110,712 KB
testcase_15 AC 393 ms
124,880 KB
testcase_16 AC 545 ms
144,924 KB
testcase_17 AC 607 ms
168,908 KB
testcase_18 AC 433 ms
128,900 KB
testcase_19 AC 599 ms
150,652 KB
testcase_20 AC 508 ms
138,996 KB
testcase_21 AC 452 ms
132,712 KB
testcase_22 AC 574 ms
142,004 KB
testcase_23 AC 281 ms
106,568 KB
testcase_24 AC 569 ms
144,516 KB
testcase_25 AC 497 ms
136,036 KB
testcase_26 AC 570 ms
145,724 KB
testcase_27 AC 458 ms
132,236 KB
testcase_28 AC 451 ms
132,216 KB
testcase_29 AC 413 ms
127,072 KB
testcase_30 AC 322 ms
112,316 KB
testcase_31 AC 381 ms
122,400 KB
testcase_32 AC 389 ms
122,124 KB
testcase_33 AC 584 ms
150,836 KB
testcase_34 AC 551 ms
144,444 KB
testcase_35 AC 380 ms
122,600 KB
testcase_36 AC 429 ms
129,704 KB
testcase_37 AC 473 ms
135,996 KB
testcase_38 AC 574 ms
149,340 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
N=int(input())
EDGE=[list(map(int,input().split())) for i in range(N-1)]
mod=10**9+7

E=[[] for i in range(N+1)]

for x,y in EDGE:
    E[x].append(y)
    E[y].append(x)

H=[0]*(N+1)

from collections import deque

QUE=deque([[1,1]])

while QUE:
    x,h=QUE.pop()
    if H[x]!=0:
        continue
    H[x]=h
    for to in E[x]:
        if H[to]==0:
            QUE.append([to,h+1])


from collections import Counter
C=Counter(H[1:])

FACT=[1,1]
FACT_INV=[1,1]
for i in range(2,2*10**5+1):
    FACT.append(FACT[-1]*i%mod)
    FACT_INV.append(FACT_INV[-1]*pow(i,mod-2,mod)%mod)
    
def Combi(N,K):
    return FACT[N]*FACT_INV[N-K]*FACT_INV[K]%mod

ANS=0
for c in C:
    ANS=(ANS+(Combi(N,c)*FACT[c-1]*FACT[N-c])*C[c]%mod)%mod

print(ANS)
0