結果

問題 No.196 典型DP (1)
ユーザー rpy3cpprpy3cpp
提出日時 2015-09-09 12:08:50
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 947 bytes
コンパイル時間 256 ms
コンパイル使用メモリ 11,060 KB
実行使用メモリ 8,928 KB
最終ジャッジ日時 2023-09-26 10:13:35
合計ジャッジ時間 9,094 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,784 KB
testcase_01 AC 15 ms
7,788 KB
testcase_02 AC 16 ms
7,928 KB
testcase_03 AC 15 ms
7,768 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 AC 16 ms
7,792 KB
testcase_07 AC 15 ms
7,744 KB
testcase_08 AC 16 ms
7,740 KB
testcase_09 AC 16 ms
7,912 KB
testcase_10 AC 16 ms
7,852 KB
testcase_11 AC 16 ms
7,752 KB
testcase_12 RE -
testcase_13 AC 17 ms
8,292 KB
testcase_14 AC 17 ms
8,236 KB
testcase_15 RE -
testcase_16 AC 51 ms
8,352 KB
testcase_17 RE -
testcase_18 AC 160 ms
8,548 KB
testcase_19 AC 198 ms
8,424 KB
testcase_20 AC 286 ms
8,700 KB
testcase_21 AC 291 ms
8,764 KB
testcase_22 RE -
testcase_23 AC 354 ms
8,876 KB
testcase_24 AC 346 ms
8,872 KB
testcase_25 AC 344 ms
8,900 KB
testcase_26 AC 22 ms
8,516 KB
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 AC 21 ms
8,544 KB
testcase_31 AC 21 ms
8,532 KB
testcase_32 AC 924 ms
8,892 KB
testcase_33 AC 926 ms
8,888 KB
testcase_34 AC 933 ms
8,836 KB
testcase_35 AC 21 ms
8,488 KB
testcase_36 AC 21 ms
8,556 KB
testcase_37 AC 312 ms
8,820 KB
testcase_38 AC 873 ms
8,928 KB
testcase_39 AC 749 ms
8,928 KB
testcase_40 AC 21 ms
8,428 KB
testcase_41 AC 15 ms
7,768 KB
testcase_42 AC 16 ms
7,812 KB
testcase_43 AC 15 ms
7,832 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):
    if K == 0:
        return 1
    if N == K:
        return 1
    root = 0
    parent = -1
    lst = f(root, parent, Es)
    lst.append(1)
    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