結果

問題 No.417 チューリップバブル
ユーザー mkawa2mkawa2
提出日時 2020-04-21 15:18:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,997 bytes
コンパイル時間 125 ms
コンパイル使用メモリ 13,056 KB
実行使用メモリ 23,296 KB
最終ジャッジ日時 2024-04-17 01:48:57
合計ジャッジ時間 13,841 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
11,136 KB
testcase_01 AC 34 ms
11,008 KB
testcase_02 AC 34 ms
11,008 KB
testcase_03 AC 33 ms
11,008 KB
testcase_04 AC 33 ms
11,136 KB
testcase_05 AC 33 ms
11,136 KB
testcase_06 AC 34 ms
11,136 KB
testcase_07 AC 34 ms
11,136 KB
testcase_08 WA -
testcase_09 AC 87 ms
11,648 KB
testcase_10 AC 197 ms
12,288 KB
testcase_11 AC 413 ms
13,440 KB
testcase_12 AC 421 ms
13,440 KB
testcase_13 AC 393 ms
11,520 KB
testcase_14 AC 875 ms
11,776 KB
testcase_15 AC 258 ms
11,264 KB
testcase_16 AC 270 ms
12,032 KB
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
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 #

from itertools import permutations
import sys

sys.setrecursionlimit(10 ** 6)
from bisect import *
from collections import *
from heapq import *

def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def SI(): return sys.stdin.readline()[:-1]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
int1 = lambda x: int(x) - 1
def MI1(): return map(int1, sys.stdin.readline().split())
def LI1(): return list(map(int1, sys.stdin.readline().split()))
p2D = lambda x: print(*x, sep="\n")
dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]

def main():
    def dfs(u=0,pu=-1):
        uu.append(u)
        for v,_ in to[u]:
            if v==pu:continue
            dfs(v,u)

    inf=10**9
    n,m=MI()
    ss=[II() for _ in range(n)]
    to=[[] for _ in range(n)]
    dist=[[inf]*n for _ in range(n)]
    for u in range(n):dist[u][u]=0
    for _ in range(n-1):
        a,b,c=MI()
        to[a].append((b,c))
        to[b].append((a,c))
        dist[a][b]=dist[b][a]=c
    # ワーシャルフロイドで村と村の所要時間を計算
    for j in range(n):
        for i in range(n):
            for k in range(n):
                dist[i][k]=min(dist[i][k],dist[i][j]+dist[j][k])
    #p2D(dist)
    # dfsで訪問順を決める
    uu=[]
    dfs()
    #print(uu)
    # dp[j][k]...最後に訪ねた村のインデックスがjで、そこまでの時間がkの場合の最大金額
    dp=[[0]*(m+1) for _ in range(n)]
    dp[0][0]=ss[0]
    for i,u in enumerate(uu[1:],1):
        s=ss[u]
        for j in range(i-1,-1,-1):
            v=uu[j]
            d=dist[u][v]
            for k in range(m-d,-1,-1):
                dp[i][k+d]=max(dp[i][k+d],dp[j][k]+s)
    ans=ss[0]
    dist0=dist[0]
    for i in range(1,n):
        u=uu[i]
        cur=max(dp[i][:m-dist0[u]+1])
        if cur>ans:ans=cur
    print(ans)

main()
0