結果

問題 No.417 チューリップバブル
ユーザー rpy3cpprpy3cpp
提出日時 2016-08-27 00:20:54
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,085 bytes
コンパイル時間 371 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 18,720 KB
最終ジャッジ日時 2024-04-26 04:22:32
合計ジャッジ時間 12,675 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
16,256 KB
testcase_01 AC 26 ms
10,880 KB
testcase_02 AC 26 ms
10,752 KB
testcase_03 AC 26 ms
10,880 KB
testcase_04 AC 27 ms
11,008 KB
testcase_05 AC 26 ms
10,880 KB
testcase_06 AC 28 ms
10,880 KB
testcase_07 AC 28 ms
10,880 KB
testcase_08 AC 83 ms
10,880 KB
testcase_09 AC 198 ms
10,880 KB
testcase_10 AC 232 ms
11,136 KB
testcase_11 AC 1,278 ms
11,136 KB
testcase_12 AC 1,263 ms
11,136 KB
testcase_13 AC 376 ms
11,008 KB
testcase_14 TLE -
testcase_15 AC 110 ms
10,880 KB
testcase_16 AC 114 ms
10,880 KB
testcase_17 AC 874 ms
11,264 KB
testcase_18 AC 893 ms
11,264 KB
testcase_19 AC 899 ms
11,136 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