結果

問題 No.827 総神童数
ユーザー OKCH3COOHOKCH3COOH
提出日時 2019-11-05 15:11:09
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,296 ms / 2,000 ms
コード長 947 bytes
コンパイル時間 219 ms
コンパイル使用メモリ 10,968 KB
実行使用メモリ 85,412 KB
最終ジャッジ日時 2023-10-13 02:19:20
合計ジャッジ時間 22,599 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,268 KB
testcase_01 AC 16 ms
7,820 KB
testcase_02 AC 16 ms
7,756 KB
testcase_03 AC 16 ms
7,952 KB
testcase_04 AC 16 ms
7,912 KB
testcase_05 AC 16 ms
7,856 KB
testcase_06 AC 16 ms
7,848 KB
testcase_07 AC 16 ms
7,980 KB
testcase_08 AC 16 ms
7,792 KB
testcase_09 AC 1,296 ms
85,412 KB
testcase_10 AC 404 ms
32,036 KB
testcase_11 AC 32 ms
9,384 KB
testcase_12 AC 169 ms
20,248 KB
testcase_13 AC 994 ms
72,300 KB
testcase_14 AC 47 ms
10,844 KB
testcase_15 AC 359 ms
33,596 KB
testcase_16 AC 998 ms
56,456 KB
testcase_17 AC 1,202 ms
68,412 KB
testcase_18 AC 483 ms
39,392 KB
testcase_19 AC 1,183 ms
60,780 KB
testcase_20 AC 835 ms
45,156 KB
testcase_21 AC 605 ms
35,264 KB
testcase_22 AC 943 ms
50,156 KB
testcase_23 AC 21 ms
8,624 KB
testcase_24 AC 1,036 ms
52,892 KB
testcase_25 AC 781 ms
42,220 KB
testcase_26 AC 1,031 ms
53,000 KB
testcase_27 AC 666 ms
38,160 KB
testcase_28 AC 668 ms
37,696 KB
testcase_29 AC 523 ms
31,928 KB
testcase_30 AC 153 ms
15,616 KB
testcase_31 AC 398 ms
26,748 KB
testcase_32 AC 384 ms
25,744 KB
testcase_33 AC 1,139 ms
57,432 KB
testcase_34 AC 1,035 ms
53,920 KB
testcase_35 AC 401 ms
27,012 KB
testcase_36 AC 587 ms
34,620 KB
testcase_37 AC 769 ms
42,080 KB
testcase_38 AC 1,114 ms
56,924 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10 ** 7)

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

def dfs(now, parent, d):
    depth[now] = d
    for to in edges[now]:
        if to == parent:
            continue
        dfs(to, now, d + 1)

dfs(0, -1, 0)

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