結果

問題 No.1308 ジャンプビーコン
ユーザー りあんりあん
提出日時 2020-12-04 19:43:36
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 876 bytes
コンパイル時間 1,744 ms
コンパイル使用メモリ 86,676 KB
実行使用メモリ 312,708 KB
最終ジャッジ日時 2023-10-13 11:11:30
合計ジャッジ時間 36,405 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,188 KB
testcase_01 AC 73 ms
71,296 KB
testcase_02 AC 72 ms
71,336 KB
testcase_03 AC 75 ms
75,016 KB
testcase_04 AC 76 ms
75,576 KB
testcase_05 AC 77 ms
75,512 KB
testcase_06 AC 75 ms
74,940 KB
testcase_07 AC 75 ms
74,780 KB
testcase_08 AC 108 ms
76,700 KB
testcase_09 AC 118 ms
77,008 KB
testcase_10 AC 102 ms
76,816 KB
testcase_11 AC 103 ms
76,252 KB
testcase_12 AC 101 ms
76,896 KB
testcase_13 AC 359 ms
79,628 KB
testcase_14 AC 389 ms
81,168 KB
testcase_15 AC 408 ms
81,984 KB
testcase_16 AC 407 ms
80,092 KB
testcase_17 AC 400 ms
80,664 KB
testcase_18 AC 3,258 ms
88,140 KB
testcase_19 AC 3,300 ms
88,964 KB
testcase_20 AC 3,498 ms
94,836 KB
testcase_21 AC 3,305 ms
90,532 KB
testcase_22 AC 3,113 ms
88,832 KB
testcase_23 AC 73 ms
71,196 KB
testcase_24 AC 91 ms
76,292 KB
testcase_25 AC 93 ms
76,476 KB
testcase_26 AC 2,627 ms
79,944 KB
testcase_27 AC 2,605 ms
80,168 KB
testcase_28 AC 2,572 ms
79,488 KB
testcase_29 TLE -
testcase_30 TLE -
testcase_31 TLE -
testcase_32 AC 3,351 ms
270,268 KB
testcase_33 AC 3,920 ms
268,704 KB
testcase_34 AC 2,261 ms
79,952 KB
testcase_35 AC 2,282 ms
81,472 KB
testcase_36 AC 2,337 ms
85,328 KB
testcase_37 AC 2,705 ms
84,396 KB
testcase_38 AC 3,223 ms
106,252 KB
testcase_39 AC 3,398 ms
107,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env pypy3

import sys
sys.setrecursionlimit(6000)

INF = 2 ** 60


def dfs_dist(p, par, g):
    if p == g:
        return 0
    for c, t in edge[p]:
        if t == par:
            continue
        d = c + dfs_dist(t, p, g)
        if d < INF:
            return d
    return INF


def dfs(p, par, l, ds):
    dp[p] += min(l, ds)
    for c, t in edge[p]:
        if t == par:
            continue
        dp[p] = min(dp[p], dfs(t, p, l + c, ds))
    return dp[p]


n, q, c = map(int, input().split())

edge = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, l = map(int, input().split())
    u -= 1
    v -= 1
    edge[u].append((l, v))
    edge[v].append((l, u))

x = list(map(lambda y: int(y) - 1, input().split()))
dp = [INF for _ in range(n)]
dp[x[0]] = 0
for prev, y in zip(x, x[1:]):
    d = dfs_dist(prev, -1, y)
    dfs(y, -1, c, d)

print(min(dp))
0