結果

問題 No.1 道のショートカット
ユーザー maninimanini
提出日時 2021-02-12 14:51:51
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,436 bytes
コンパイル時間 348 ms
コンパイル使用メモリ 87,064 KB
実行使用メモリ 81,520 KB
最終ジャッジ日時 2023-09-26 13:49:37
合計ジャッジ時間 9,009 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,188 KB
testcase_01 AC 75 ms
71,288 KB
testcase_02 AC 75 ms
71,260 KB
testcase_03 AC 77 ms
71,384 KB
testcase_04 AC 75 ms
71,444 KB
testcase_05 AC 74 ms
71,092 KB
testcase_06 AC 75 ms
71,436 KB
testcase_07 AC 75 ms
71,436 KB
testcase_08 AC 244 ms
79,576 KB
testcase_09 AC 213 ms
80,236 KB
testcase_10 AC 161 ms
79,940 KB
testcase_11 AC 175 ms
80,156 KB
testcase_12 AC 263 ms
81,520 KB
testcase_13 AC 257 ms
81,516 KB
testcase_14 AC 130 ms
77,928 KB
testcase_15 AC 72 ms
71,340 KB
testcase_16 WA -
testcase_17 AC 72 ms
71,344 KB
testcase_18 AC 144 ms
78,396 KB
testcase_19 AC 188 ms
79,724 KB
testcase_20 AC 158 ms
78,968 KB
testcase_21 WA -
testcase_22 AC 175 ms
78,984 KB
testcase_23 AC 178 ms
80,412 KB
testcase_24 AC 191 ms
79,732 KB
testcase_25 AC 204 ms
80,752 KB
testcase_26 AC 160 ms
79,124 KB
testcase_27 AC 218 ms
80,232 KB
testcase_28 AC 113 ms
77,428 KB
testcase_29 AC 125 ms
78,492 KB
testcase_30 AC 95 ms
76,812 KB
testcase_31 AC 107 ms
78,120 KB
testcase_32 AC 193 ms
79,440 KB
testcase_33 AC 171 ms
79,864 KB
testcase_34 AC 181 ms
79,836 KB
testcase_35 AC 83 ms
76,372 KB
testcase_36 AC 131 ms
78,432 KB
testcase_37 WA -
testcase_38 AC 82 ms
76,148 KB
testcase_39 WA -
testcase_40 AC 108 ms
77,956 KB
testcase_41 AC 77 ms
75,852 KB
testcase_42 AC 72 ms
71,084 KB
testcase_43 AC 71 ms
71,340 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding:UTF-8
import sys
from heapq import heappush, heappop

MOD = 10 ** 9 + 7
INF = float('inf')

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()))     # スペース区切り連続数字

# ダイクストラ O((E+N)logN)
dist = [[] for _ in range(N)]    # dist[n]: ノード n に隣接する(ノード, 重み)をリストで持つ
for i in range(V):
    s = S[i] - 1
    t = T[i] - 1
    c = Y[i]
    d = M[i]
    dist[s].append((t, c, d))
    dist[t].append((s, c, d))

ns = 0
hq = [(0, C, 0)]   # (distance, node)
dist_min = [[INF] * (C + 1) for _ in range(N)]
dist_min[ns][C] = 0
seen = [[False] * (C + 1) for _ in range(N)]

while hq:
    d, c, v = heappop(hq)   # ノードを pop する
    if seen[v][c]:
        continue
    seen[v][c] = True
    for to, cost, dis in dist[v]:    # ノード v に隣接しているノードに対して
        if c - cost >= 0 and seen[to][c - cost] == False and d + dis < dist_min[to][c - cost]:
            dist_min[to][c - cost] = d + dis
            heappush(hq, (dist_min[to][c - cost], c - cost, to))

res = min(dist_min[N-1])
if res == INF:
    res = -1
print("{}".format(res))
0