結果

問題 No.417 チューリップバブル
ユーザー rpy3cpprpy3cpp
提出日時 2016-08-27 00:11:29
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 886 bytes
コンパイル時間 98 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 16,384 KB
最終ジャッジ日時 2024-04-26 04:16:26
合計ジャッジ時間 10,523 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
16,384 KB
testcase_01 AC 30 ms
11,008 KB
testcase_02 AC 30 ms
11,008 KB
testcase_03 WA -
testcase_04 AC 30 ms
11,008 KB
testcase_05 AC 30 ms
10,880 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 WA -
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
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) if dpv[k - i - cost])

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