結果

問題 No.827 総神童数
ユーザー OKCH3COOHOKCH3COOH
提出日時 2019-11-05 15:13:41
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,301 ms / 2,000 ms
コード長 960 bytes
コンパイル時間 72 ms
コンパイル使用メモリ 11,064 KB
実行使用メモリ 65,144 KB
最終ジャッジ日時 2023-10-13 02:20:39
合計ジャッジ時間 23,481 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,556 KB
testcase_01 AC 18 ms
8,528 KB
testcase_02 AC 19 ms
8,600 KB
testcase_03 AC 18 ms
8,736 KB
testcase_04 AC 18 ms
8,632 KB
testcase_05 AC 19 ms
8,616 KB
testcase_06 AC 19 ms
8,720 KB
testcase_07 AC 18 ms
8,748 KB
testcase_08 AC 19 ms
8,600 KB
testcase_09 AC 1,257 ms
65,144 KB
testcase_10 AC 413 ms
28,700 KB
testcase_11 AC 36 ms
9,548 KB
testcase_12 AC 182 ms
17,280 KB
testcase_13 AC 962 ms
54,176 KB
testcase_14 AC 52 ms
10,496 KB
testcase_15 AC 365 ms
26,916 KB
testcase_16 AC 972 ms
54,572 KB
testcase_17 AC 1,177 ms
62,900 KB
testcase_18 AC 479 ms
32,176 KB
testcase_19 AC 1,301 ms
61,052 KB
testcase_20 AC 924 ms
45,364 KB
testcase_21 AC 664 ms
35,528 KB
testcase_22 AC 1,020 ms
50,320 KB
testcase_23 AC 25 ms
8,916 KB
testcase_24 AC 1,112 ms
53,012 KB
testcase_25 AC 817 ms
42,472 KB
testcase_26 AC 1,117 ms
53,216 KB
testcase_27 AC 736 ms
38,476 KB
testcase_28 AC 705 ms
38,144 KB
testcase_29 AC 587 ms
32,188 KB
testcase_30 AC 171 ms
15,756 KB
testcase_31 AC 453 ms
26,876 KB
testcase_32 AC 412 ms
26,104 KB
testcase_33 AC 1,233 ms
57,756 KB
testcase_34 AC 1,112 ms
54,132 KB
testcase_35 AC 440 ms
27,448 KB
testcase_36 AC 633 ms
34,872 KB
testcase_37 AC 823 ms
42,488 KB
testcase_38 AC 1,200 ms
57,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

class Combination:
    def __init__(self, size, mod=10**9 + 7):
        self.size = size + 2
        self.mod = mod
        self.fact = [1, 1] + [0] * size
        self.inv = [0, 1] + [0] * size

        for i in range(2, self.size):
            self.fact[i] = self.fact[i - 1] * i % self.mod
            self.inv[i] = -self.inv[self.mod % i] * (self.mod // i) % self.mod

N = int(input())
MOD = 10**9 + 7
edges = [[] for _ in range(N)]

for _ in range(N - 1):
    fr, to = map(int, input().split())
    fr -= 1
    to -= 1
    edges[fr].append(to)
    edges[to].append(fr)

depth = [-1] * N

st = deque([(0, -1, 0)])
while st:
    now, pr, d = st.pop()
    depth[now] = d
    for to in edges[now]:
        if to == pr:
            continue
        st.append((to, now, d + 1))

comb = Combination(N + 10)
ans = 0
facN = comb.fact[N]
inv = comb.inv
for i in range(N):
    ans += facN * inv[depth[i] + 1]
    ans %= MOD

print(ans)
0