結果

問題 No.827 総神童数
ユーザー titiatitia
提出日時 2019-05-03 23:45:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 774 bytes
コンパイル時間 151 ms
コンパイル使用メモリ 10,952 KB
実行使用メモリ 103,264 KB
最終ジャッジ日時 2023-08-30 06:45:29
合計ジャッジ時間 50,223 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 780 ms
24,264 KB
testcase_01 AC 771 ms
24,256 KB
testcase_02 AC 771 ms
24,228 KB
testcase_03 AC 775 ms
24,156 KB
testcase_04 AC 774 ms
24,156 KB
testcase_05 AC 767 ms
24,068 KB
testcase_06 AC 771 ms
24,072 KB
testcase_07 AC 772 ms
24,292 KB
testcase_08 AC 769 ms
24,200 KB
testcase_09 TLE -
testcase_10 AC 1,174 ms
52,444 KB
testcase_11 AC 784 ms
25,460 KB
testcase_12 AC 930 ms
35,716 KB
testcase_13 AC 1,786 ms
84,960 KB
testcase_14 AC 796 ms
26,812 KB
testcase_15 AC 1,114 ms
50,244 KB
testcase_16 AC 1,659 ms
85,064 KB
testcase_17 AC 1,888 ms
94,720 KB
testcase_18 AC 1,207 ms
56,744 KB
testcase_19 AC 1,751 ms
88,044 KB
testcase_20 AC 1,464 ms
70,408 KB
testcase_21 AC 1,241 ms
57,236 KB
testcase_22 AC 1,538 ms
75,244 KB
testcase_23 AC 773 ms
24,572 KB
testcase_24 AC 1,606 ms
80,072 KB
testcase_25 AC 1,378 ms
66,280 KB
testcase_26 AC 1,608 ms
79,268 KB
testcase_27 AC 1,280 ms
60,868 KB
testcase_28 AC 1,275 ms
60,168 KB
testcase_29 AC 1,170 ms
53,372 KB
testcase_30 AC 875 ms
32,956 KB
testcase_31 AC 1,070 ms
46,256 KB
testcase_32 AC 1,071 ms
45,704 KB
testcase_33 AC 1,731 ms
85,284 KB
testcase_34 AC 1,620 ms
80,332 KB
testcase_35 AC 1,069 ms
46,464 KB
testcase_36 AC 1,247 ms
56,544 KB
testcase_37 AC 1,373 ms
65,928 KB
testcase_38 AC 1,721 ms
83,748 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