結果

問題 No.1 道のショートカット
ユーザー akasia_midoriakasia_midori
提出日時 2022-05-03 10:57:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 108 ms / 5,000 ms
コード長 989 bytes
コンパイル時間 506 ms
コンパイル使用メモリ 87,036 KB
実行使用メモリ 77,776 KB
最終ジャッジ日時 2023-09-15 08:51:23
合計ジャッジ時間 6,682 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
70,844 KB
testcase_01 AC 78 ms
71,056 KB
testcase_02 AC 79 ms
70,544 KB
testcase_03 AC 76 ms
70,916 KB
testcase_04 AC 80 ms
70,972 KB
testcase_05 AC 78 ms
70,936 KB
testcase_06 AC 80 ms
70,968 KB
testcase_07 AC 80 ms
70,672 KB
testcase_08 AC 99 ms
76,392 KB
testcase_09 AC 84 ms
75,384 KB
testcase_10 AC 86 ms
75,540 KB
testcase_11 AC 93 ms
76,536 KB
testcase_12 AC 91 ms
76,224 KB
testcase_13 AC 93 ms
76,536 KB
testcase_14 AC 79 ms
70,900 KB
testcase_15 AC 76 ms
70,956 KB
testcase_16 AC 81 ms
75,380 KB
testcase_17 AC 77 ms
71,252 KB
testcase_18 AC 79 ms
70,932 KB
testcase_19 AC 77 ms
70,800 KB
testcase_20 AC 81 ms
75,380 KB
testcase_21 AC 78 ms
70,900 KB
testcase_22 AC 78 ms
70,900 KB
testcase_23 AC 108 ms
77,776 KB
testcase_24 AC 92 ms
76,652 KB
testcase_25 AC 80 ms
75,396 KB
testcase_26 AC 78 ms
71,060 KB
testcase_27 AC 96 ms
76,524 KB
testcase_28 AC 76 ms
70,904 KB
testcase_29 AC 90 ms
76,584 KB
testcase_30 AC 81 ms
75,336 KB
testcase_31 AC 84 ms
75,424 KB
testcase_32 AC 87 ms
75,568 KB
testcase_33 AC 84 ms
75,320 KB
testcase_34 AC 92 ms
76,348 KB
testcase_35 AC 89 ms
75,904 KB
testcase_36 AC 85 ms
75,628 KB
testcase_37 AC 85 ms
75,144 KB
testcase_38 AC 78 ms
71,052 KB
testcase_39 AC 81 ms
70,900 KB
testcase_40 AC 85 ms
75,392 KB
testcase_41 AC 80 ms
70,728 KB
testcase_42 AC 80 ms
71,052 KB
testcase_43 AC 78 ms
71,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

import heapq

input_count = 0
N = int(input())
C = int(input())
V = int(input())

S = many_int()
T = many_int()
Y = many_int()
M = many_int()

G = {i:[] for i in range(N)}
temp_G = {i:set([]) for i in range(N)}

for i in range(V):
    temp_G[S[i]-1].add(f"{T[i]-1}_{M[i]}_{Y[i]}")
    
for k, v in temp_G.items():
    
    for vv in v:
        t,m,y = vv.split("_")
        G[k].append((int(t), int(m), int(y)))

G

q = [[0,0,0]]

mins = 10**10
while q:
    all_minute, all_cost, now_node = heapq.heappop(q)
    if now_node == (N-1):
        mins = min(mins, all_minute)
        break
        continue
    
    for next_node, next_minute, next_cost in G[now_node]:
        if (all_cost + next_cost) > C:
            continue
        else:
            heapq.heappush(q, (all_minute+next_minute, all_cost+next_cost, next_node))
            

if mins == 10**10:
    print(-1)
else:
    print(mins)
0