結果

問題 No.1308 ジャンプビーコン
ユーザー りあんりあん
提出日時 2020-12-04 20:12:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 3,848 ms / 4,000 ms
コード長 1,043 bytes
コンパイル時間 398 ms
コンパイル使用メモリ 87,028 KB
実行使用メモリ 312,344 KB
最終ジャッジ日時 2023-10-13 11:12:39
合計ジャッジ時間 57,750 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
71,508 KB
testcase_01 AC 96 ms
71,592 KB
testcase_02 AC 95 ms
71,588 KB
testcase_03 AC 100 ms
76,156 KB
testcase_04 AC 101 ms
76,688 KB
testcase_05 AC 102 ms
76,700 KB
testcase_06 AC 100 ms
76,364 KB
testcase_07 AC 102 ms
76,128 KB
testcase_08 AC 125 ms
77,524 KB
testcase_09 AC 135 ms
78,184 KB
testcase_10 AC 125 ms
77,184 KB
testcase_11 AC 121 ms
77,276 KB
testcase_12 AC 120 ms
77,264 KB
testcase_13 AC 368 ms
81,972 KB
testcase_14 AC 323 ms
79,896 KB
testcase_15 AC 358 ms
81,220 KB
testcase_16 AC 357 ms
81,656 KB
testcase_17 AC 352 ms
82,912 KB
testcase_18 AC 2,769 ms
88,880 KB
testcase_19 AC 2,789 ms
88,220 KB
testcase_20 AC 2,897 ms
93,392 KB
testcase_21 AC 2,828 ms
89,288 KB
testcase_22 AC 2,469 ms
85,988 KB
testcase_23 AC 92 ms
71,640 KB
testcase_24 AC 119 ms
77,904 KB
testcase_25 AC 115 ms
77,916 KB
testcase_26 AC 1,987 ms
80,924 KB
testcase_27 AC 1,939 ms
80,128 KB
testcase_28 AC 1,881 ms
80,848 KB
testcase_29 AC 3,718 ms
312,344 KB
testcase_30 AC 3,703 ms
269,940 KB
testcase_31 AC 2,969 ms
269,168 KB
testcase_32 AC 3,214 ms
268,156 KB
testcase_33 AC 3,848 ms
268,868 KB
testcase_34 AC 2,039 ms
81,704 KB
testcase_35 AC 2,083 ms
81,076 KB
testcase_36 AC 2,460 ms
84,640 KB
testcase_37 AC 2,494 ms
84,860 KB
testcase_38 AC 2,813 ms
102,180 KB
testcase_39 AC 2,836 ms
103,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env pypy3

import sys
from collections import deque
sys.setrecursionlimit(6000)

INF = 2 ** 60


def get_dist(s, g):
    if s == g:
        return 0
    dist = [INF for _ in edge]
    dist[s] = 0
    q = deque()
    q.append(s)
    while True:
        p = q.popleft()
        for c, t in edge[p]:
            if t == g:
                return dist[p] + c
            if dist[t] == INF:
                dist[t] = dist[p] + c
                q.append(t)


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 = get_dist(prev, y)
    dfs(y, -1, c, d)

print(min(dp))
0