結果

問題 No.417 チューリップバブル
ユーザー rpy3cpprpy3cpp
提出日時 2016-08-27 00:20:54
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
TLE  
実行時間 -
コード長 1,085 bytes
コンパイル時間 290 ms
コンパイル使用メモリ 10,888 KB
実行使用メモリ 14,308 KB
最終ジャッジ日時 2023-08-08 11:21:19
合計ジャッジ時間 12,682 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
12,632 KB
testcase_01 AC 16 ms
8,348 KB
testcase_02 AC 16 ms
8,252 KB
testcase_03 AC 16 ms
8,320 KB
testcase_04 AC 15 ms
8,380 KB
testcase_05 AC 16 ms
8,392 KB
testcase_06 AC 17 ms
8,204 KB
testcase_07 AC 17 ms
8,416 KB
testcase_08 AC 74 ms
8,372 KB
testcase_09 AC 176 ms
8,464 KB
testcase_10 AC 221 ms
8,400 KB
testcase_11 AC 1,133 ms
8,620 KB
testcase_12 AC 1,120 ms
8,604 KB
testcase_13 AC 357 ms
8,520 KB
testcase_14 AC 1,799 ms
8,644 KB
testcase_15 AC 102 ms
8,380 KB
testcase_16 AC 102 ms
8,432 KB
testcase_17 AC 820 ms
8,840 KB
testcase_18 AC 836 ms
8,812 KB
testcase_19 AC 833 ms
8,744 KB
testcase_20 TLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

def read_data():
    N, M = map(int, input().split())
    Us = [int(input()) for i in range(N)]
    dist = [dict() for i in range(N)]
    for n in range(N - 1):
        a, b, c = map(int, input().split())
        dist[a][b] = c
        dist[b][a] = c
    return N, M, Us, dist

def solve(N, M, Us, dist):
    M2 = M // 2
    used = [False] * N
    dp = [[0] * (M2 + 1) for i in range(N)]
    dfs(0, Us, dist, dp, used, M2)
    return max(dp[0][:M2 + 1])

def dfs(v, Us, dist, dp, used, M2):
    used[v] = True
    dp[v][0] = Us[v]
    dpv = dp[v]
    for u, cost in dist[v].items():
        if used[u]:
            continue
        dfs(u, Us, dist, dp, used, M2)
        dpu = dp[u]
        merge_dp(dpv, dpu, M2, cost)


def merge_dp(dpv, dpu, M2, cost):
    for k in range(M2, cost - 1, -1):
        dpvk = dpv[k]
        for i in range(k - cost + 1):
            dpv0 = dpv[k - i - cost]
            dpui = dpu[i]
            if dpv0 and dpui and dpv0 + dpui > dpvk:
                dpvk = dpv0 + dpui
        dpv[k] = dpvk

N, M, Us, dist = read_data()
print(solve(N, M, Us, dist))
0