結果

問題 No.1308 ジャンプビーコン
ユーザー りあんりあん
提出日時 2020-12-04 18:43:36
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 814 bytes
コンパイル時間 277 ms
コンパイル使用メモリ 86,900 KB
実行使用メモリ 107,716 KB
最終ジャッジ日時 2023-10-13 13:51:08
合計ジャッジ時間 42,583 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,208 KB
testcase_01 AC 69 ms
71,400 KB
testcase_02 AC 65 ms
71,316 KB
testcase_03 AC 72 ms
75,000 KB
testcase_04 AC 77 ms
75,776 KB
testcase_05 AC 72 ms
75,536 KB
testcase_06 AC 72 ms
75,212 KB
testcase_07 AC 73 ms
75,204 KB
testcase_08 AC 100 ms
77,052 KB
testcase_09 AC 108 ms
77,020 KB
testcase_10 AC 93 ms
76,820 KB
testcase_11 AC 94 ms
76,732 KB
testcase_12 AC 95 ms
77,024 KB
testcase_13 AC 325 ms
79,768 KB
testcase_14 AC 350 ms
81,336 KB
testcase_15 AC 365 ms
82,400 KB
testcase_16 AC 383 ms
80,012 KB
testcase_17 AC 367 ms
80,900 KB
testcase_18 AC 3,124 ms
88,380 KB
testcase_19 AC 3,254 ms
88,972 KB
testcase_20 AC 3,082 ms
94,560 KB
testcase_21 AC 2,703 ms
90,460 KB
testcase_22 AC 2,672 ms
88,764 KB
testcase_23 AC 67 ms
71,204 KB
testcase_24 AC 78 ms
76,444 KB
testcase_25 AC 78 ms
76,432 KB
testcase_26 AC 2,162 ms
79,856 KB
testcase_27 AC 2,069 ms
80,100 KB
testcase_28 AC 2,145 ms
79,564 KB
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 AC 2,202 ms
79,868 KB
testcase_35 AC 2,234 ms
81,312 KB
testcase_36 AC 2,496 ms
85,052 KB
testcase_37 AC 2,595 ms
84,096 KB
testcase_38 AC 3,000 ms
105,816 KB
testcase_39 AC 3,126 ms
107,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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