結果

問題 No.196 典型DP (1)
ユーザー mkawa2mkawa2
提出日時 2023-01-12 11:46:16
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,845 bytes
コンパイル時間 323 ms
コンパイル使用メモリ 87,212 KB
実行使用メモリ 119,552 KB
最終ジャッジ日時 2023-08-24 19:53:35
合計ジャッジ時間 9,595 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,288 KB
testcase_01 AC 72 ms
71,244 KB
testcase_02 AC 74 ms
71,368 KB
testcase_03 AC 72 ms
71,500 KB
testcase_04 AC 72 ms
71,368 KB
testcase_05 AC 72 ms
71,408 KB
testcase_06 AC 72 ms
71,288 KB
testcase_07 AC 71 ms
71,224 KB
testcase_08 AC 71 ms
71,120 KB
testcase_09 AC 73 ms
71,268 KB
testcase_10 AC 72 ms
71,308 KB
testcase_11 AC 71 ms
71,308 KB
testcase_12 WA -
testcase_13 AC 78 ms
75,992 KB
testcase_14 AC 80 ms
75,772 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 110 ms
78,092 KB
testcase_27 AC 117 ms
78,028 KB
testcase_28 AC 121 ms
78,332 KB
testcase_29 AC 137 ms
88,108 KB
testcase_30 AC 142 ms
87,756 KB
testcase_31 AC 111 ms
78,164 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 433 ms
96,700 KB
testcase_36 AC 106 ms
78,448 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 438 ms
96,492 KB
testcase_41 AC 72 ms
71,400 KB
testcase_42 AC 71 ms
71,588 KB
testcase_43 AC 72 ms
71,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(1000005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = (1 << 63)-1
# inf = (1 << 31)-1
md = 10**9+7
# md = 998244353

n, k = LI()
to = [[] for _ in range(n)]
for _ in range(n-1):
    u, v = LI()
    to[u].append(v)
    to[v].append(u)

parent, depth, vis = [-1]*n, [0]*n, [0]*n

def dfs(root):
    uu = []
    vis[root] = 1
    stack = [root]
    while stack:
        iu = stack.pop()
        i, u = divmod(iu, n)
        if i == 0:
            uu.append(u)
        # care to's format
        while i < len(to[u]) and vis[to[u][i]]: i += 1
        if i < len(to[u]):
            stack.append((i+1)*n+u)
            # care to's format
            v = to[u][i]
            vis[v] = 1
            stack.append(v)
            parent[v] = u
            depth[v] = depth[u]+1

    return uu

uu = dfs(0)
size = [1]*n
for u in uu[:0:-1]:
    p = parent[u]
    size[p] += size[u]

def merge(p, u):
    m = min(k+1, len(dp[p])+len(dp[u])-1)
    cur = [0]*m
    for s, c in enumerate(dp[p]):
        for t, d in enumerate(dp[u]):
            if s+t >= m: break
            cur[s+t] += c*d
    dp[p] = cur

dp = [[1] for _ in range(n)]
for u in uu[::-1]:
    if len(dp[u]) <= k: dp[u].append(1)
    p = parent[u]
    merge(p, u)

print(dp[0][k])
0