結果

問題 No.827 総神童数
ユーザー AEnAEn
提出日時 2022-11-20 23:19:59
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
TLE  
実行時間 -
コード長 718 bytes
コンパイル時間 109 ms
コンパイル使用メモリ 11,944 KB
実行使用メモリ 101,260 KB
最終ジャッジ日時 2023-10-21 18:35:11
合計ジャッジ時間 37,480 ms
ジャッジサーバーID
(参考情報)
judge12 / judge10
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,068 KB
testcase_01 AC 29 ms
10,068 KB
testcase_02 AC 29 ms
10,068 KB
testcase_03 AC 30 ms
10,068 KB
testcase_04 AC 31 ms
10,068 KB
testcase_05 AC 30 ms
10,068 KB
testcase_06 AC 30 ms
10,068 KB
testcase_07 AC 30 ms
10,068 KB
testcase_08 AC 30 ms
10,068 KB
testcase_09 TLE -
testcase_10 AC 712 ms
39,000 KB
testcase_11 AC 58 ms
11,456 KB
testcase_12 AC 314 ms
24,344 KB
testcase_13 AC 1,675 ms
85,196 KB
testcase_14 AC 90 ms
13,076 KB
testcase_15 AC 658 ms
39,944 KB
testcase_16 AC 1,701 ms
70,164 KB
testcase_17 TLE -
testcase_18 AC 844 ms
47,092 KB
testcase_19 AC 1,946 ms
61,268 KB
testcase_20 AC 1,421 ms
46,140 KB
testcase_21 AC 1,044 ms
36,448 KB
testcase_22 AC 1,559 ms
51,008 KB
testcase_23 AC 40 ms
10,376 KB
testcase_24 AC 1,728 ms
53,468 KB
testcase_25 AC 1,305 ms
43,220 KB
testcase_26 AC 1,719 ms
53,756 KB
testcase_27 AC 1,154 ms
39,328 KB
testcase_28 AC 1,139 ms
38,888 KB
testcase_29 AC 909 ms
33,296 KB
testcase_30 AC 285 ms
17,276 KB
testcase_31 AC 748 ms
28,196 KB
testcase_32 AC 682 ms
27,480 KB
testcase_33 AC 1,902 ms
57,968 KB
testcase_34 AC 1,739 ms
54,624 KB
testcase_35 AC 723 ms
28,404 KB
testcase_36 AC 1,024 ms
35,936 KB
testcase_37 AC 1,302 ms
43,160 KB
testcase_38 AC 1,864 ms
57,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**8)

mod = 10**9+7
N = int(input())
G = [list() for _ in range(N)]
for i in range(N-1):
    u, v = map(int,input().split())
    u-=1;v-=1
    G[u].append(v)
    G[v].append(u)

fac = [0]*(N+1)
inv = [0]*(N+1)
fac[0]=1;inv[0]=1
for i in range(1,N+1):
    fac[i] = (fac[i-1]*i)%mod
    inv[i] = (inv[i-1]*pow(i,mod-2,mod))%mod

def ncr(r):
    return (fac[N]*inv[r]*inv[N-r])%mod

res = (N*fac[N-1])%mod
depth = [0]*N
depth[0] = 1
def dfs(v,p):
    for nex in G[v]:
        if nex==p:
            continue
        depth[nex] = depth[v]+1
        global res
        res += ncr(depth[nex])*fac[depth[nex]-1]*fac[N-depth[nex]]
        res %= mod
        dfs(nex,v)

dfs(0,-1)
print(res)
0