結果

問題 No.196 典型DP (1)
ユーザー sibasyunsibasyun
提出日時 2024-02-24 20:36:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 166 ms / 2,000 ms
コード長 1,143 bytes
コンパイル時間 253 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 89,116 KB
最終ジャッジ日時 2024-02-24 20:36:55
合計ジャッジ時間 6,310 ms
ジャッジサーバーID
(参考情報)
judge13 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
55,752 KB
testcase_01 AC 41 ms
55,752 KB
testcase_02 AC 43 ms
55,752 KB
testcase_03 AC 42 ms
55,752 KB
testcase_04 AC 42 ms
55,752 KB
testcase_05 AC 42 ms
55,752 KB
testcase_06 AC 42 ms
55,752 KB
testcase_07 AC 42 ms
55,752 KB
testcase_08 AC 42 ms
55,752 KB
testcase_09 AC 43 ms
55,752 KB
testcase_10 AC 43 ms
55,752 KB
testcase_11 AC 43 ms
55,752 KB
testcase_12 AC 47 ms
61,544 KB
testcase_13 AC 49 ms
61,932 KB
testcase_14 AC 51 ms
64,192 KB
testcase_15 AC 56 ms
66,244 KB
testcase_16 AC 68 ms
70,648 KB
testcase_17 AC 90 ms
76,032 KB
testcase_18 AC 96 ms
76,720 KB
testcase_19 AC 116 ms
76,956 KB
testcase_20 AC 110 ms
76,940 KB
testcase_21 AC 135 ms
76,956 KB
testcase_22 AC 109 ms
76,956 KB
testcase_23 AC 117 ms
79,128 KB
testcase_24 AC 114 ms
79,128 KB
testcase_25 AC 114 ms
78,092 KB
testcase_26 AC 122 ms
89,116 KB
testcase_27 AC 122 ms
88,856 KB
testcase_28 AC 130 ms
89,112 KB
testcase_29 AC 122 ms
89,116 KB
testcase_30 AC 124 ms
89,116 KB
testcase_31 AC 141 ms
76,696 KB
testcase_32 AC 139 ms
76,696 KB
testcase_33 AC 139 ms
76,696 KB
testcase_34 AC 138 ms
76,696 KB
testcase_35 AC 144 ms
76,692 KB
testcase_36 AC 166 ms
76,812 KB
testcase_37 AC 139 ms
76,940 KB
testcase_38 AC 144 ms
76,812 KB
testcase_39 AC 140 ms
76,824 KB
testcase_40 AC 141 ms
76,944 KB
testcase_41 AC 42 ms
55,752 KB
testcase_42 AC 43 ms
55,752 KB
testcase_43 AC 43 ms
55,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import io
import sys
import bisect
import math
from itertools import permutations, combinations
from heapq import heappush, heappop
from collections import deque
from collections import defaultdict as dd
sys.setrecursionlimit(10**7+10)

# mod = 998244353
mod = 10**9+7

_INPUT = """\
6 1
0 1
0 2
1 3
2 4
2 5

"""



def main():
    N, K = map(int, input().split())
    G = [[]for _ in range(N)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        G[a].append(b)
        G[b].append(a)
    def dfs(now, par):
        dp = [1] # 黒が0個となる場合の数
        for nxt in G[now]:
            if nxt == par:continue

            ndp = dfs(nxt, now)
            merged = [0]*(len(dp)+len(ndp)-1)

            for i in range(len(dp)):
                for j in range(len(ndp)):
                    merged[i+j] += dp[i]*ndp[j]
                    merged[i+j] %= mod
            dp = merged
        dp.append(dp[-1]) # 自分以外全部黒と、全部黒は同数
        return dp
    
    print(dfs(0, -1)[K])   
                            
if __name__ == "__main__":
    # sys.stdin = io.StringIO(_INPUT)
    main()
0