結果

問題 No.417 チューリップバブル
ユーザー mkawa2mkawa2
提出日時 2020-04-21 14:40:32
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,977 bytes
コンパイル時間 293 ms
コンパイル使用メモリ 13,056 KB
実行使用メモリ 16,256 KB
最終ジャッジ日時 2024-04-17 00:19:18
合計ジャッジ時間 7,898 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
16,256 KB
testcase_01 AC 33 ms
10,752 KB
testcase_02 AC 32 ms
10,752 KB
testcase_03 AC 34 ms
10,752 KB
testcase_04 AC 31 ms
10,880 KB
testcase_05 AC 31 ms
10,880 KB
testcase_06 AC 33 ms
10,880 KB
testcase_07 AC 34 ms
10,752 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
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):
        for j in range(i-1,-1,-1):
            v=uu[j]
            d=dist[u][v]
            for k in range(m,-1,-1):
                if k+d<=m:dp[i][k+d]=max(dp[i][k+d],dp[j][k]+ss[u])
    ans=ss[0]
    dist0=dist[0]
    for u in range(1,n):
        cur=max(dp[u][:m-dist0[u]+1])
        if cur>ans:ans=cur
    print(ans)

main()
0