結果

問題 No.196 典型DP (1)
ユーザー rpy3cpprpy3cpp
提出日時 2015-09-09 12:06:16
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 864 bytes
コンパイル時間 146 ms
コンパイル使用メモリ 10,800 KB
実行使用メモリ 8,932 KB
最終ジャッジ日時 2023-09-26 10:13:25
合計ジャッジ時間 13,085 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,832 KB
testcase_01 AC 16 ms
7,820 KB
testcase_02 RE -
testcase_03 AC 16 ms
7,860 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 16 ms
7,792 KB
testcase_08 AC 16 ms
7,752 KB
testcase_09 AC 16 ms
7,744 KB
testcase_10 AC 16 ms
7,748 KB
testcase_11 AC 17 ms
7,856 KB
testcase_12 RE -
testcase_13 AC 17 ms
7,792 KB
testcase_14 AC 17 ms
8,160 KB
testcase_15 RE -
testcase_16 AC 52 ms
8,352 KB
testcase_17 RE -
testcase_18 AC 160 ms
8,472 KB
testcase_19 AC 197 ms
8,596 KB
testcase_20 AC 290 ms
8,880 KB
testcase_21 AC 289 ms
8,736 KB
testcase_22 RE -
testcase_23 AC 354 ms
8,896 KB
testcase_24 AC 343 ms
8,832 KB
testcase_25 AC 346 ms
8,876 KB
testcase_26 AC 21 ms
8,520 KB
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 AC 926 ms
8,776 KB
testcase_32 AC 934 ms
8,776 KB
testcase_33 AC 924 ms
8,724 KB
testcase_34 AC 925 ms
8,860 KB
testcase_35 AC 924 ms
8,740 KB
testcase_36 AC 875 ms
8,788 KB
testcase_37 AC 310 ms
8,932 KB
testcase_38 AC 865 ms
8,824 KB
testcase_39 AC 744 ms
8,780 KB
testcase_40 AC 904 ms
8,828 KB
testcase_41 AC 16 ms
7,788 KB
testcase_42 AC 16 ms
7,912 KB
testcase_43 AC 15 ms
7,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def read_data():
    N, K = map(int, input().split())
    Es = [[] for i in range(N)]
    for i in range(N - 1):
        a, b = map(int, input().split())
        Es[a].append(b)
        Es[b].append(a)
    return N, K, Es


def solve(N, K, Es):
    root = 0
    parent = -1
    lst = f(root, parent, Es)
    return lst[K]


def f(node, parent, Es):
    if len(Es[node]) == 1:
        return [1, 1]
    lst = [1]
    for child in Es[node]:
        if child == parent:
            continue
        lst_c = f(child, node, Es)
        lst = merge(lst, lst_c)
    lst.append(1)
    return lst


def merge(lst1, lst2):
    mod = 10**9 + 7
    lst = [0] * (len(lst1) + len(lst2) - 1)
    for i, vi in enumerate(lst1):
        for j, vj in enumerate(lst2):
            lst[i + j] += vi * vj
    return [v % mod for v in lst]


N, K, Es = read_data()
print(solve(N, K, Es))
0