結果

問題 No.417 チューリップバブル
ユーザー rpy3cpprpy3cpp
提出日時 2016-08-27 00:05:53
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
WA  
実行時間 -
コード長 865 bytes
コンパイル時間 239 ms
コンパイル使用メモリ 11,028 KB
実行使用メモリ 12,588 KB
最終ジャッジ日時 2023-08-08 11:11:04
合計ジャッジ時間 10,347 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
12,588 KB
testcase_01 AC 17 ms
8,284 KB
testcase_02 AC 17 ms
8,312 KB
testcase_03 WA -
testcase_04 AC 16 ms
8,320 KB
testcase_05 AC 16 ms
8,424 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 1,805 ms
9,140 KB
testcase_13 WA -
testcase_14 TLE -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
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]
        for k in range(M2, cost - 1, -1):
            dpv[k] = max(dpv[k - i - cost] + dpu[i] for i in range(k - cost + 1))

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