結果

問題 No.827 総神童数
ユーザー ttrttr
提出日時 2020-02-26 15:22:35
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 979 bytes
コンパイル時間 718 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 73,792 KB
最終ジャッジ日時 2024-04-21 16:26:34
合計ジャッジ時間 35,075 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,752 KB
testcase_01 AC 34 ms
10,880 KB
testcase_02 AC 35 ms
10,752 KB
testcase_03 AC 31 ms
10,880 KB
testcase_04 AC 31 ms
10,880 KB
testcase_05 AC 30 ms
10,880 KB
testcase_06 AC 31 ms
10,880 KB
testcase_07 AC 30 ms
10,752 KB
testcase_08 AC 30 ms
10,752 KB
testcase_09 TLE -
testcase_10 AC 640 ms
33,120 KB
testcase_11 AC 56 ms
11,904 KB
testcase_12 AC 285 ms
20,608 KB
testcase_13 AC 1,502 ms
61,212 KB
testcase_14 AC 81 ms
12,928 KB
testcase_15 AC 601 ms
31,400 KB
testcase_16 AC 1,531 ms
61,904 KB
testcase_17 AC 1,837 ms
70,976 KB
testcase_18 AC 771 ms
37,236 KB
testcase_19 AC 1,854 ms
69,656 KB
testcase_20 AC 1,335 ms
52,492 KB
testcase_21 AC 962 ms
41,212 KB
testcase_22 AC 1,460 ms
57,764 KB
testcase_23 AC 40 ms
11,136 KB
testcase_24 AC 1,597 ms
61,316 KB
testcase_25 AC 1,214 ms
49,108 KB
testcase_26 AC 1,618 ms
61,364 KB
testcase_27 AC 1,054 ms
44,712 KB
testcase_28 AC 1,045 ms
44,184 KB
testcase_29 AC 827 ms
37,496 KB
testcase_30 AC 259 ms
19,200 KB
testcase_31 AC 644 ms
31,840 KB
testcase_32 AC 621 ms
30,928 KB
testcase_33 AC 1,768 ms
66,152 KB
testcase_34 AC 1,631 ms
62,156 KB
testcase_35 AC 662 ms
31,944 KB
testcase_36 AC 935 ms
41,088 KB
testcase_37 AC 1,210 ms
49,056 KB
testcase_38 AC 1,772 ms
65,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
E = [[] for _ in range(N)]
for _ in range(N-1):
    u,v = map(int, input().split())
    E[u-1].append(v-1)
    E[v-1].append(u-1)

from collections import deque
q = deque()
q.append((0, 0))
rnk = [-1]*N
rnk[0] = 0
while q:
    temp = q.popleft()
    u = temp[0]
    r = temp[1]
    for v in E[u]:
        if rnk[v] >= 0:
            continue
        rnk[v] = r+1
        q.append((v, r+1))

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

ans = g1[N]
for i in range(1, N):
    ans += cmb(N, rnk[i]+1, mod) * g1[rnk[i]] * g1[N-rnk[i]-1]
    ans %= mod

print(ans)
0