結果

問題 No.827 総神童数
ユーザー OKCH3COOHOKCH3COOH
提出日時 2019-11-05 15:08:10
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 1,412 bytes
コンパイル時間 223 ms
コンパイル使用メモリ 10,824 KB
実行使用メモリ 68,360 KB
最終ジャッジ日時 2023-10-13 02:18:04
合計ジャッジ時間 23,954 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,056 KB
testcase_01 AC 16 ms
8,200 KB
testcase_02 AC 16 ms
8,128 KB
testcase_03 AC 17 ms
8,128 KB
testcase_04 AC 17 ms
8,040 KB
testcase_05 AC 16 ms
8,084 KB
testcase_06 AC 16 ms
8,092 KB
testcase_07 AC 16 ms
8,120 KB
testcase_08 AC 16 ms
8,232 KB
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 AC 1,297 ms
68,360 KB
testcase_20 AC 912 ms
51,016 KB
testcase_21 AC 661 ms
39,656 KB
testcase_22 AC 1,021 ms
56,244 KB
testcase_23 AC 22 ms
8,480 KB
testcase_24 AC 1,112 ms
59,648 KB
testcase_25 AC 838 ms
47,404 KB
testcase_26 AC 1,112 ms
59,808 KB
testcase_27 AC 723 ms
42,868 KB
testcase_28 AC 712 ms
42,240 KB
testcase_29 AC 568 ms
35,768 KB
testcase_30 AC 168 ms
16,728 KB
testcase_31 AC 445 ms
29,692 KB
testcase_32 AC 423 ms
28,788 KB
testcase_33 AC 1,233 ms
64,744 KB
testcase_34 AC 1,110 ms
60,948 KB
testcase_35 AC 458 ms
29,684 KB
testcase_36 AC 640 ms
38,820 KB
testcase_37 AC 824 ms
47,204 KB
testcase_38 AC 1,201 ms
64,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Combination:
    def __init__(self, size, mod=10**9 + 7):
        self.size = size + 2
        self.mod = mod
        self.fact = [1, 1] + [0] * size
        self.factInv = [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
            self.factInv[i] = self.factInv[i - 1] * self.inv[i] % self.mod

    def npr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * self.factInv[n - r] % self.mod

    def ncr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * (self.factInv[r] * self.factInv[n - r] % self.mod) % self.mod

    def factN(self, n):
        if n < 0:
            return 0
        return self.fact[n]

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
for i in range(N):
    ans += comb.factN(N) * comb.inv[depth[i] + 1]
    ans %= MOD

print(ans)
0