結果

問題 No.2805 Go to School
ユーザー 2000 Ekiben2000 Ekiben
提出日時 2024-07-12 21:58:30
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,263 bytes
コンパイル時間 320 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 267,408 KB
最終ジャッジ日時 2024-07-12 21:59:12
合計ジャッジ時間 25,633 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
55,160 KB
testcase_01 AC 42 ms
55,304 KB
testcase_02 AC 42 ms
54,700 KB
testcase_03 AC 41 ms
55,056 KB
testcase_04 AC 874 ms
171,420 KB
testcase_05 WA -
testcase_06 AC 499 ms
121,596 KB
testcase_07 AC 696 ms
166,724 KB
testcase_08 AC 574 ms
124,780 KB
testcase_09 AC 464 ms
125,620 KB
testcase_10 AC 1,722 ms
266,536 KB
testcase_11 AC 1,133 ms
179,176 KB
testcase_12 AC 1,557 ms
218,184 KB
testcase_13 AC 333 ms
108,804 KB
testcase_14 AC 41 ms
54,800 KB
testcase_15 AC 41 ms
56,088 KB
testcase_16 AC 41 ms
54,684 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 1,104 ms
182,820 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 369 ms
134,488 KB
testcase_25 AC 1,097 ms
267,408 KB
testcase_26 AC 615 ms
206,068 KB
testcase_27 AC 93 ms
83,232 KB
testcase_28 AC 134 ms
101,708 KB
testcase_29 AC 299 ms
154,376 KB
testcase_30 AC 581 ms
146,212 KB
testcase_31 AC 810 ms
264,860 KB
testcase_32 AC 1,275 ms
256,984 KB
testcase_33 AC 64 ms
69,388 KB
testcase_34 AC 66 ms
70,560 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 1,044 ms
217,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq, sys
from collections import defaultdict

input = sys.stdin.read
data = input().split()

N, M, L, S, E = map(int, data[:5])
paths = [(int(data[i]), int(data[i+1]), int(data[i+2])) for i in range(5, 5 + 3 * M, 3)]
toilets = list(map(int, data[5 + 3 * M:]))

g = defaultdict(dict)
for a, b, t in paths:
    g[a][b] = min(g[a].get(b, float('inf')), t)
    g[b][a] = min(g[b].get(a, float('inf')), t)

def dijkstra(g, start):
    d = {i: float('inf') for i in g}
    d[start] = 0
    q = [(0, start)]
    while q:
        cd, cn = heapq.heappop(q)
        if cd > d[cn]: continue
        for n, w in g[cn].items():
            dist = cd + w
            if dist < d[n]:
                d[n] = dist
                heapq.heappush(q, (dist, n))
    return d

try:
    mt = dijkstra(g, 1)
    rg = defaultdict(dict)
    for a in g:
        for b in g[a]:
            rg[b][a] = g[a][b]
    mf = dijkstra(rg, N)
    min_t = float('inf')
    for t in toilets:
        at = mt[t]
        if at < S:
            tt = S + 1 + mf[t]
        elif at <= S + E - 0.99:
            tt = at + 1 + mf[t]
        else:
            continue
        if tt < min_t:
            min_t = tt
    print(-1 if min_t == float('inf') else int(min_t))
except KeyError:
    print(-1)
0