結果

問題 No.1308 ジャンプビーコン
ユーザー りあんりあん
提出日時 2020-12-04 20:30:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,360 ms / 4,000 ms
コード長 1,420 bytes
コンパイル時間 1,890 ms
コンパイル使用メモリ 87,224 KB
実行使用メモリ 91,752 KB
最終ジャッジ日時 2023-10-13 10:13:18
合計ジャッジ時間 39,783 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
71,768 KB
testcase_01 AC 90 ms
71,760 KB
testcase_02 AC 91 ms
71,760 KB
testcase_03 AC 101 ms
77,000 KB
testcase_04 AC 103 ms
76,908 KB
testcase_05 AC 101 ms
76,912 KB
testcase_06 AC 100 ms
76,792 KB
testcase_07 AC 103 ms
77,016 KB
testcase_08 AC 136 ms
77,744 KB
testcase_09 AC 145 ms
77,520 KB
testcase_10 AC 136 ms
77,812 KB
testcase_11 AC 137 ms
77,800 KB
testcase_12 AC 139 ms
77,824 KB
testcase_13 AC 252 ms
78,588 KB
testcase_14 AC 256 ms
78,640 KB
testcase_15 AC 259 ms
78,464 KB
testcase_16 AC 259 ms
78,268 KB
testcase_17 AC 257 ms
78,588 KB
testcase_18 AC 2,059 ms
89,100 KB
testcase_19 AC 1,974 ms
89,504 KB
testcase_20 AC 2,161 ms
91,528 KB
testcase_21 AC 1,975 ms
91,508 KB
testcase_22 AC 1,852 ms
87,944 KB
testcase_23 AC 88 ms
71,872 KB
testcase_24 AC 129 ms
78,724 KB
testcase_25 AC 129 ms
78,668 KB
testcase_26 AC 1,435 ms
90,312 KB
testcase_27 AC 1,393 ms
90,128 KB
testcase_28 AC 1,404 ms
89,472 KB
testcase_29 AC 1,787 ms
90,356 KB
testcase_30 AC 1,767 ms
90,828 KB
testcase_31 AC 2,045 ms
91,752 KB
testcase_32 AC 1,731 ms
90,520 KB
testcase_33 AC 2,177 ms
90,060 KB
testcase_34 AC 1,466 ms
89,816 KB
testcase_35 AC 1,445 ms
91,108 KB
testcase_36 AC 1,700 ms
87,972 KB
testcase_37 AC 1,589 ms
86,256 KB
testcase_38 AC 2,120 ms
89,036 KB
testcase_39 AC 2,360 ms
90,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env pypy3

from collections import deque

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 calc(s, dp, l, ds):
    res = [i for i in dp]
    dist = [INF for _ in dp]
    vis = [False for _ in dp]
    st = deque()
    st.append(s)
    dist[s] = l

    while st:
        p = st[-1]
        if vis[p]:
            st.pop()
            for c, t in edge[p]:
                if dist[p] < dist[t]:
                    res[p] = min(res[p], res[t])
        else:
            vis[p] = True
            res[p] += min(dist[p], ds)
            for c, t in edge[p]:
                if dist[t] == INF:
                    dist[t] = dist[p] + c
                    st.append(t)

    return res


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)
    dp = calc(y, dp, c, d)

print(min(dp))
0