結果

問題 No.417 チューリップバブル
ユーザー maspymaspy
提出日時 2020-03-07 05:15:15
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,267 ms / 2,000 ms
コード長 1,138 bytes
コンパイル時間 312 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 44,528 KB
最終ジャッジ日時 2024-04-22 11:51:34
合計ジャッジ時間 31,175 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 467 ms
44,272 KB
testcase_01 AC 462 ms
43,888 KB
testcase_02 AC 459 ms
44,016 KB
testcase_03 AC 461 ms
44,148 KB
testcase_04 AC 469 ms
44,272 KB
testcase_05 AC 461 ms
44,396 KB
testcase_06 AC 461 ms
44,276 KB
testcase_07 AC 482 ms
44,024 KB
testcase_08 AC 494 ms
44,268 KB
testcase_09 AC 498 ms
44,268 KB
testcase_10 AC 526 ms
44,396 KB
testcase_11 AC 595 ms
44,528 KB
testcase_12 AC 582 ms
44,276 KB
testcase_13 AC 562 ms
44,140 KB
testcase_14 AC 644 ms
44,404 KB
testcase_15 AC 498 ms
44,012 KB
testcase_16 AC 506 ms
44,408 KB
testcase_17 AC 647 ms
44,272 KB
testcase_18 AC 650 ms
44,400 KB
testcase_19 AC 674 ms
44,272 KB
testcase_20 AC 865 ms
44,140 KB
testcase_21 AC 858 ms
44,400 KB
testcase_22 AC 871 ms
44,528 KB
testcase_23 AC 872 ms
44,276 KB
testcase_24 AC 468 ms
44,140 KB
testcase_25 AC 854 ms
44,284 KB
testcase_26 AC 552 ms
44,400 KB
testcase_27 AC 732 ms
44,016 KB
testcase_28 AC 845 ms
44,404 KB
testcase_29 AC 847 ms
44,152 KB
testcase_30 AC 842 ms
44,272 KB
testcase_31 AC 871 ms
44,016 KB
testcase_32 AC 468 ms
44,276 KB
testcase_33 AC 475 ms
44,272 KB
testcase_34 AC 668 ms
44,404 KB
testcase_35 AC 1,267 ms
44,272 KB
testcase_36 AC 1,226 ms
44,400 KB
testcase_37 AC 1,238 ms
44,412 KB
testcase_38 AC 1,253 ms
44,020 KB
testcase_39 AC 1,240 ms
44,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

# %%
N, M = map(int, readline().split())
U = [int(readline()) for _ in range(N)]
m = map(int, read().split())
ABC = zip(m, m, m)

# %%
graph = [[] for _ in range(N)]
for a, b, c in ABC:
    graph[a].append((b, c))
    graph[b].append((a, c))

# %%
root = 0
parent = [0] * N
order = []
stack = [root]
while stack:
    x = stack.pop()
    order.append(x)
    for y, _ in graph[x]:
        if y == parent[x]:
            continue
        parent[y] = x
        stack.append(y)

M //= 2

# %%


def merge(A, B):
    C = np.zeros(M + 1, np.int64)
    for i, x in enumerate(A):
        np.maximum(C[i:], B[: M + 1 - i] + x, out=C[i:])
    return C


# %%
dp = [None] * N
for v in order[::-1]:
    A = np.zeros(M + 1, np.int64)
    A[0] = U[v]
    for w, cost in graph[v]:
        if cost > M or w == parent[v]:
            continue
        B = np.zeros(M + 1, np.int64)
        B[cost: M + 1] = dp[w][: M + 1 - cost]
        A = merge(A, B)
    dp[v] = A


# %%
print(dp[0].max())
0