結果

問題 No.1 道のショートカット
ユーザー rlangevinrlangevin
提出日時 2023-11-17 00:45:11
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,669 bytes
コンパイル時間 197 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 78,128 KB
最終ジャッジ日時 2023-11-17 00:45:17
合計ジャッジ時間 5,210 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 37 ms
53,460 KB
testcase_02 AC 36 ms
53,460 KB
testcase_03 AC 38 ms
53,460 KB
testcase_04 AC 36 ms
53,460 KB
testcase_05 AC 37 ms
53,460 KB
testcase_06 AC 37 ms
53,460 KB
testcase_07 AC 37 ms
53,460 KB
testcase_08 AC 48 ms
62,324 KB
testcase_09 AC 43 ms
59,456 KB
testcase_10 AC 46 ms
61,556 KB
testcase_11 AC 48 ms
62,324 KB
testcase_12 AC 97 ms
76,876 KB
testcase_13 AC 92 ms
77,048 KB
testcase_14 AC 39 ms
53,460 KB
testcase_15 AC 37 ms
53,460 KB
testcase_16 WA -
testcase_17 AC 37 ms
53,460 KB
testcase_18 AC 38 ms
53,460 KB
testcase_19 AC 38 ms
53,460 KB
testcase_20 AC 41 ms
59,456 KB
testcase_21 AC 39 ms
53,460 KB
testcase_22 AC 37 ms
53,460 KB
testcase_23 AC 48 ms
64,444 KB
testcase_24 AC 46 ms
62,324 KB
testcase_25 AC 40 ms
59,456 KB
testcase_26 AC 38 ms
53,460 KB
testcase_27 AC 49 ms
62,324 KB
testcase_28 AC 39 ms
53,460 KB
testcase_29 AC 81 ms
77,140 KB
testcase_30 AC 48 ms
62,228 KB
testcase_31 AC 43 ms
59,456 KB
testcase_32 WA -
testcase_33 AC 102 ms
76,840 KB
testcase_34 WA -
testcase_35 AC 45 ms
61,556 KB
testcase_36 AC 119 ms
76,876 KB
testcase_37 AC 114 ms
76,596 KB
testcase_38 AC 45 ms
61,704 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 53 ms
63,912 KB
testcase_42 AC 37 ms
53,460 KB
testcase_43 AC 38 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from heapq import heappush, heappop
inf = 10 ** 18


def dijkstra(s, g, N):
    # ゴールがない場合はg=-1とする。

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

    dist = [inf] * N
    mindist = [inf] * N
    seen = [False] * N
    par = [(-1, -1)] * 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, par

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

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


N = int(input())
C = int(input())
V = int(input())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
Y = list(map(int, input().split()))
M = list(map(int, input().split()))
D = []
dic = dict()
for i in range(V):
    S[i], T[i] = S[i] - 1, T[i] - 1
    D.append((Y[i], S[i], T[i], M[i], i))
    dic[i] = Y[i]
    
D.sort()
for _ in range(V):
    G = [[] for i in range(N)]
    for y, s, t, m, ind in D:
        G[s].append((t, m, ind))
    dist, P = dijkstra(0, N - 1, N)
    val = 0
    now = N - 1
    while now != 0:
        if P[now][0] == -1:
            break
        val += dic[P[now][1]]
        now = P[now][0]
    if val <= C and dist[-1] != inf:
        print(dist[-1])
        exit()
    D.pop()
        
print(-1)
0