結果

問題 No.2805 Go to School
ユーザー 👑 rin204rin204
提出日時 2024-07-12 21:21:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 596 ms / 2,000 ms
コード長 981 bytes
コンパイル時間 199 ms
コンパイル使用メモリ 81,976 KB
実行使用メモリ 120,464 KB
最終ジャッジ日時 2024-07-16 01:37:23
合計ジャッジ時間 12,192 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
54,088 KB
testcase_01 AC 37 ms
53,628 KB
testcase_02 AC 38 ms
53,264 KB
testcase_03 AC 38 ms
54,432 KB
testcase_04 AC 303 ms
101,372 KB
testcase_05 AC 458 ms
98,880 KB
testcase_06 AC 292 ms
87,824 KB
testcase_07 AC 287 ms
88,160 KB
testcase_08 AC 395 ms
100,356 KB
testcase_09 AC 333 ms
87,876 KB
testcase_10 AC 178 ms
84,820 KB
testcase_11 AC 377 ms
111,800 KB
testcase_12 AC 239 ms
93,208 KB
testcase_13 AC 355 ms
100,132 KB
testcase_14 AC 106 ms
82,980 KB
testcase_15 AC 38 ms
53,240 KB
testcase_16 AC 38 ms
53,104 KB
testcase_17 AC 37 ms
52,900 KB
testcase_18 AC 412 ms
92,480 KB
testcase_19 AC 281 ms
87,332 KB
testcase_20 AC 527 ms
100,632 KB
testcase_21 AC 563 ms
109,152 KB
testcase_22 AC 309 ms
94,412 KB
testcase_23 AC 434 ms
98,880 KB
testcase_24 AC 442 ms
96,336 KB
testcase_25 AC 264 ms
89,820 KB
testcase_26 AC 585 ms
120,464 KB
testcase_27 AC 302 ms
109,928 KB
testcase_28 AC 84 ms
82,880 KB
testcase_29 AC 92 ms
83,160 KB
testcase_30 AC 166 ms
100,536 KB
testcase_31 AC 297 ms
91,208 KB
testcase_32 AC 473 ms
117,996 KB
testcase_33 AC 596 ms
111,952 KB
testcase_34 AC 57 ms
64,392 KB
testcase_35 AC 57 ms
66,448 KB
testcase_36 AC 259 ms
88,956 KB
testcase_37 AC 280 ms
91,896 KB
testcase_38 AC 249 ms
98,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *

n, m, l, s, e = map(int, input().split())
edges = [[] for _ in range(n)]

for _ in range(m):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    edges[u].append((v, w))
    edges[v].append((u, w))

T = list(map(int, input().split()))
tf = [False] * n
for t in T:
    tf[t - 1] = True

inf = 1 << 60
dist = [[inf] * n for _ in range(2)]
dist[0][0] = 0
hq = [0]
while hq:
    tmp = heappop(hq)
    t = tmp & 1
    tmp >>= 1
    d = tmp // n
    pos = tmp - d * n
    if dist[t][pos] < d:
        continue
    for npos, c in edges[pos]:
        nd = d + c
        if t == 0 and nd >= s + e:
            continue
        if nd < dist[t][npos]:
            dist[t][npos] = nd
            heappush(hq, (nd * n + npos) * 2 + t)

    if t == 0 and tf[pos]:
        nd = max(s, d) + 1
        if nd < dist[1][pos]:
            dist[1][pos] = nd
            heappush(hq, (nd * n + pos) * 2 + 1)

ans = dist[1][n - 1]
if ans == inf:
    ans = -1
print(ans)
0