結果

問題 No.2805 Go to School
ユーザー rlangevinrlangevin
提出日時 2024-07-12 21:27:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,096 ms / 2,000 ms
コード長 1,389 bytes
コンパイル時間 167 ms
コンパイル使用メモリ 82,276 KB
実行使用メモリ 124,496 KB
最終ジャッジ日時 2024-07-16 01:37:42
合計ジャッジ時間 17,977 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,608 KB
testcase_01 AC 40 ms
52,480 KB
testcase_02 AC 40 ms
52,224 KB
testcase_03 AC 40 ms
52,736 KB
testcase_04 AC 343 ms
104,740 KB
testcase_05 AC 549 ms
99,124 KB
testcase_06 AC 390 ms
89,092 KB
testcase_07 AC 389 ms
88,892 KB
testcase_08 AC 475 ms
99,796 KB
testcase_09 AC 456 ms
89,216 KB
testcase_10 AC 347 ms
89,120 KB
testcase_11 AC 1,096 ms
123,988 KB
testcase_12 AC 730 ms
104,932 KB
testcase_13 AC 956 ms
116,112 KB
testcase_14 AC 258 ms
86,912 KB
testcase_15 AC 40 ms
52,480 KB
testcase_16 AC 41 ms
52,736 KB
testcase_17 AC 39 ms
52,352 KB
testcase_18 AC 617 ms
97,280 KB
testcase_19 AC 464 ms
91,784 KB
testcase_20 AC 732 ms
105,340 KB
testcase_21 AC 1,009 ms
124,496 KB
testcase_22 AC 555 ms
100,228 KB
testcase_23 AC 729 ms
104,580 KB
testcase_24 AC 745 ms
105,436 KB
testcase_25 AC 243 ms
88,960 KB
testcase_26 AC 603 ms
120,500 KB
testcase_27 AC 363 ms
115,200 KB
testcase_28 AC 95 ms
84,992 KB
testcase_29 AC 107 ms
86,272 KB
testcase_30 AC 184 ms
107,904 KB
testcase_31 AC 376 ms
94,348 KB
testcase_32 AC 503 ms
117,348 KB
testcase_33 AC 713 ms
115,724 KB
testcase_34 AC 66 ms
67,072 KB
testcase_35 AC 67 ms
67,840 KB
testcase_36 AC 442 ms
92,396 KB
testcase_37 AC 445 ms
97,876 KB
testcase_38 AC 740 ms
114,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush, heappop
inf = float('inf')
def dijkstra(s, g, G):
    # ゴールがない場合はg=-1とする。

    N = len(G)

    def cost(v, m):
        return v * N + m

    dist = [inf] * N
    mindist = [inf] * N
    seen = [False] * N
    Q = [cost(0, s)]
    while Q:
        c, m = divmod(heappop(Q), N)
        if seen[m]:
            continue
        seen[m] = True
        dist[m] = c
        if m == g:
            return dist

        #------heapをアップデートする。--------
        for u, C in G[m]:
            if seen[u]:
                continue
            newdist = dist[m] + C

            #------------------------------------
            if newdist >= mindist[u]:
                continue
            mindist[u] = newdist
            heappush(Q, cost(newdist, u))
    return dist

N, M, L, S, E = map(int, input().split())
G = [[] for i in range(N)]
for i in range(M):
    u, v, c = map(int, input().split())
    u, v = u - 1, v - 1
    G[u].append((v, c))
    G[v].append((u, c))

T = list(map(int, input().split()))
D0 = dijkstra(0, -1, G)
DN = dijkstra(N - 1, -1, G)
if D0[-1] <= S + E - 1:
    print(max(S + 1, D0[-1] + 1))
    exit()
    
inf = 10 ** 18
ans = inf
for i in range(L):
    if D0[T[i]-1] >= S + E:
        continue
    ans = min(ans, max(S + 1, D0[T[i]-1] + 1) + DN[T[i]-1])
    
print(ans) if ans < inf//2 else print(-1)
0