結果

問題 No.1 道のショートカット
ユーザー brthyyjpbrthyyjp
提出日時 2021-10-30 02:30:55
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,180 bytes
コンパイル時間 243 ms
コンパイル使用メモリ 82,292 KB
実行使用メモリ 96,416 KB
最終ジャッジ日時 2024-04-16 16:07:23
合計ジャッジ時間 6,929 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
53,248 KB
testcase_01 AC 42 ms
53,120 KB
testcase_02 AC 44 ms
53,120 KB
testcase_03 AC 42 ms
53,248 KB
testcase_04 AC 41 ms
52,608 KB
testcase_05 AC 42 ms
53,248 KB
testcase_06 AC 42 ms
53,120 KB
testcase_07 AC 42 ms
52,864 KB
testcase_08 AC 219 ms
92,032 KB
testcase_09 AC 193 ms
84,552 KB
testcase_10 AC 154 ms
81,024 KB
testcase_11 AC 158 ms
84,560 KB
testcase_12 AC 267 ms
96,416 KB
testcase_13 AC 257 ms
95,580 KB
testcase_14 AC 128 ms
78,420 KB
testcase_15 AC 47 ms
59,648 KB
testcase_16 WA -
testcase_17 AC 52 ms
62,592 KB
testcase_18 AC 127 ms
78,008 KB
testcase_19 AC 171 ms
80,260 KB
testcase_20 AC 151 ms
80,668 KB
testcase_21 WA -
testcase_22 AC 145 ms
79,196 KB
testcase_23 AC 182 ms
91,264 KB
testcase_24 AC 216 ms
93,904 KB
testcase_25 AC 171 ms
82,944 KB
testcase_26 AC 155 ms
81,024 KB
testcase_27 AC 210 ms
90,368 KB
testcase_28 AC 99 ms
77,312 KB
testcase_29 AC 112 ms
78,744 KB
testcase_30 AC 73 ms
71,296 KB
testcase_31 AC 76 ms
75,008 KB
testcase_32 AC 202 ms
87,956 KB
testcase_33 AC 183 ms
84,080 KB
testcase_34 AC 195 ms
88,704 KB
testcase_35 AC 59 ms
66,560 KB
testcase_36 AC 119 ms
78,692 KB
testcase_37 WA -
testcase_38 AC 60 ms
65,536 KB
testcase_39 WA -
testcase_40 AC 89 ms
77,312 KB
testcase_41 AC 62 ms
65,792 KB
testcase_42 AC 43 ms
53,248 KB
testcase_43 AC 48 ms
60,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
INF = 10**18
def dijkstra(s, edge):
    n = len(edge)
    dist = [INF]*n
    dist[s] = 0
    edgelist = []
    heapq.heappush(edgelist,(dist[s], s))
    while edgelist:
        minedge = heapq.heappop(edgelist)
        if dist[minedge[1]] < minedge[0]:
            continue
        v = minedge[1]
        for e in edge[v]:
            if dist[e[1]] > dist[v]+e[0]:
                dist[e[1]] = dist[v]+e[0]
                heapq.heappush(edgelist,(dist[e[1]], e[1]))
    return dist

n = int(input())
c = int(input())
a = 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()))

N = n*(c+1)
edge = [[] for i in range(N)]
for i in range(a):
    s, t, y, m = S[i], T[i], Y[i], M[i]
    s, t = s-1, t-1
    for j in range(c+1):
        if j+y <= c:
            edge[n*j+s].append((m, n*(j+y)+t))
    for j in range(c+1):
        if j+y <= c:
            edge[n*j+t].append((m, n*(j+y)+s))

dist = dijkstra(0, edge)
ans = INF
for i in range(N):
    cost, v = divmod(i, n)
    if v == n-1:
        ans = min(dist[i], ans)
if ans < INF:
    print(ans)
else:
    print(-1)
0