結果

問題 No.1308 ジャンプビーコン
ユーザー mkawa2mkawa2
提出日時 2023-12-27 01:04:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,340 ms / 4,000 ms
コード長 1,549 bytes
コンパイル時間 145 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 98,492 KB
最終ジャッジ日時 2023-12-27 01:04:32
合計ジャッジ時間 27,165 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,460 KB
testcase_01 AC 40 ms
53,460 KB
testcase_02 AC 38 ms
53,460 KB
testcase_03 AC 42 ms
59,584 KB
testcase_04 AC 41 ms
59,456 KB
testcase_05 AC 44 ms
59,584 KB
testcase_06 AC 43 ms
59,456 KB
testcase_07 AC 45 ms
59,584 KB
testcase_08 AC 86 ms
76,256 KB
testcase_09 AC 82 ms
76,228 KB
testcase_10 AC 83 ms
76,100 KB
testcase_11 AC 112 ms
76,092 KB
testcase_12 AC 81 ms
76,124 KB
testcase_13 AC 147 ms
76,248 KB
testcase_14 AC 147 ms
76,216 KB
testcase_15 AC 145 ms
76,288 KB
testcase_16 AC 147 ms
76,224 KB
testcase_17 AC 143 ms
76,320 KB
testcase_18 AC 1,173 ms
88,328 KB
testcase_19 AC 1,319 ms
89,596 KB
testcase_20 AC 1,298 ms
90,472 KB
testcase_21 AC 1,149 ms
89,980 KB
testcase_22 AC 1,212 ms
90,772 KB
testcase_23 AC 37 ms
53,460 KB
testcase_24 AC 80 ms
76,272 KB
testcase_25 AC 63 ms
73,428 KB
testcase_26 AC 1,307 ms
94,360 KB
testcase_27 AC 1,300 ms
96,276 KB
testcase_28 AC 1,268 ms
93,836 KB
testcase_29 AC 1,203 ms
88,592 KB
testcase_30 AC 1,318 ms
90,640 KB
testcase_31 AC 1,159 ms
88,972 KB
testcase_32 AC 984 ms
90,756 KB
testcase_33 AC 1,295 ms
89,024 KB
testcase_34 AC 1,299 ms
97,476 KB
testcase_35 AC 1,340 ms
98,492 KB
testcase_36 AC 1,245 ms
92,332 KB
testcase_37 AC 1,275 ms
92,728 KB
testcase_38 AC 1,277 ms
90,364 KB
testcase_39 AC 1,277 ms
89,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(1000005)
# sys.set_int_max_str_digits(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
# inf = -1-(-1 << 31)
inf = -1-(-1 << 62)

# md = 10**9+7
md = 998244353

n,q,c=LI()
to=[[] for _ in range(n)]
for _ in range(n-1):
    u,v,l=LI1()
    l+=1
    to[u].append((v,l))
    to[v].append((u,l))
xx=LI1()

def dfs(root=0):
    uu, stack = [], [root]
    while stack:
        u = stack.pop()
        uu.append(u)
        for v,l in to[u]:
            if v == parent[u]: continue
            parent[v] = u
            depth[v] = depth[u]+l
            stack.append(v)
    return uu

dp=[inf]*n
dp[xx[0]]=0
for s,t in zip(xx,xx[1:]):
    dp,pre=[inf]*n,dp
    parent, depth = [-1]*n, [0]*n
    uu = dfs(t)
    for u in uu[::-1]:
        dp[u] = min(dp[u], pre[u]+depth[u]+c,pre[u]+depth[s])
        if u==s:dp[u]=min(dp[u],min(pre)+depth[s])
        if u==t:break
        p=parent[u]
        dp[p]=min(dp[p],dp[u])
    # print(t,dp)

print(min(dp))
0