結果

問題 No.196 典型DP (1)
ユーザー rpy3cpprpy3cpp
提出日時 2015-09-09 12:17:51
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 955 bytes
コンパイル時間 643 ms
コンパイル使用メモリ 86,920 KB
実行使用メモリ 101,640 KB
最終ジャッジ日時 2023-09-26 10:14:15
合計ジャッジ時間 7,895 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,508 KB
testcase_01 AC 70 ms
71,304 KB
testcase_02 AC 70 ms
71,332 KB
testcase_03 AC 69 ms
71,428 KB
testcase_04 AC 71 ms
71,440 KB
testcase_05 AC 71 ms
71,472 KB
testcase_06 AC 69 ms
71,396 KB
testcase_07 AC 72 ms
71,360 KB
testcase_08 AC 70 ms
71,424 KB
testcase_09 AC 70 ms
71,336 KB
testcase_10 AC 71 ms
71,552 KB
testcase_11 AC 71 ms
71,388 KB
testcase_12 AC 74 ms
75,472 KB
testcase_13 AC 75 ms
75,520 KB
testcase_14 AC 78 ms
76,424 KB
testcase_15 AC 88 ms
76,744 KB
testcase_16 AC 101 ms
77,088 KB
testcase_17 AC 125 ms
77,836 KB
testcase_18 AC 149 ms
78,508 KB
testcase_19 AC 158 ms
79,076 KB
testcase_20 AC 190 ms
79,536 KB
testcase_21 AC 207 ms
79,328 KB
testcase_22 AC 202 ms
79,672 KB
testcase_23 AC 217 ms
101,640 KB
testcase_24 AC 189 ms
83,068 KB
testcase_25 AC 214 ms
98,312 KB
testcase_26 AC 98 ms
77,080 KB
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 AC 99 ms
76,984 KB
testcase_31 AC 95 ms
77,004 KB
testcase_32 AC 197 ms
78,160 KB
testcase_33 AC 195 ms
78,100 KB
testcase_34 AC 201 ms
78,012 KB
testcase_35 AC 94 ms
77,044 KB
testcase_36 AC 94 ms
77,040 KB
testcase_37 AC 175 ms
78,768 KB
testcase_38 AC 192 ms
78,600 KB
testcase_39 AC 183 ms
78,312 KB
testcase_40 AC 94 ms
76,740 KB
testcase_41 AC 71 ms
71,396 KB
testcase_42 AC 71 ms
71,244 KB
testcase_43 AC 70 ms
71,260 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 node and 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