結果

問題 No.1 道のショートカット
ユーザー OKCH3COOHOKCH3COOH
提出日時 2019-10-23 21:02:17
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 277 ms / 5,000 ms
コード長 984 bytes
コンパイル時間 254 ms
コンパイル使用メモリ 11,008 KB
実行使用メモリ 11,736 KB
最終ジャッジ日時 2023-09-27 22:23:40
合計ジャッジ時間 3,364 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,564 KB
testcase_01 AC 18 ms
8,564 KB
testcase_02 AC 18 ms
8,564 KB
testcase_03 AC 18 ms
8,740 KB
testcase_04 AC 19 ms
8,568 KB
testcase_05 AC 19 ms
8,740 KB
testcase_06 AC 19 ms
8,648 KB
testcase_07 AC 18 ms
8,568 KB
testcase_08 AC 23 ms
8,764 KB
testcase_09 AC 20 ms
8,708 KB
testcase_10 AC 23 ms
8,844 KB
testcase_11 AC 56 ms
9,164 KB
testcase_12 AC 38 ms
9,044 KB
testcase_13 AC 31 ms
8,876 KB
testcase_14 AC 19 ms
8,624 KB
testcase_15 AC 20 ms
8,624 KB
testcase_16 AC 19 ms
8,612 KB
testcase_17 AC 20 ms
8,568 KB
testcase_18 AC 18 ms
8,584 KB
testcase_19 AC 19 ms
8,576 KB
testcase_20 AC 19 ms
8,596 KB
testcase_21 AC 19 ms
8,712 KB
testcase_22 AC 18 ms
8,564 KB
testcase_23 AC 133 ms
10,472 KB
testcase_24 AC 55 ms
9,296 KB
testcase_25 AC 20 ms
8,652 KB
testcase_26 AC 19 ms
8,592 KB
testcase_27 AC 166 ms
10,244 KB
testcase_28 AC 18 ms
8,776 KB
testcase_29 AC 60 ms
8,964 KB
testcase_30 AC 21 ms
8,776 KB
testcase_31 AC 277 ms
11,736 KB
testcase_32 AC 27 ms
8,784 KB
testcase_33 AC 22 ms
8,752 KB
testcase_34 AC 168 ms
10,448 KB
testcase_35 AC 21 ms
8,940 KB
testcase_36 AC 24 ms
8,760 KB
testcase_37 AC 24 ms
8,832 KB
testcase_38 AC 18 ms
8,752 KB
testcase_39 AC 18 ms
8,736 KB
testcase_40 AC 20 ms
8,664 KB
testcase_41 AC 19 ms
8,644 KB
testcase_42 AC 19 ms
8,628 KB
testcase_43 AC 19 ms
8,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

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()))

edges = [[] for _ in range(N)]

for fr, to, cost, time in zip(S, T, Y, M):
    fr -= 1
    to -= 1
    edges[fr].append((to, cost, time))

que = deque([(0, 0, 0)])
minDist = [(float('inf'), float('inf'))] * N
ans = float('inf')
while que:
    now, cost, time = que.popleft()

    if minDist[now][0] <= cost and minDist[now][1] <= time:
        continue
    elif minDist[now][0] > cost and minDist[now][1] > time:
        minDist[now] = (cost, time)

    if now == N - 1:
        ans = min(ans, time)
        continue

    for to, c, t in edges[now]:
        if c + cost > C or (minDist[to][0] <= cost and minDist[to][1] <= time):
            continue
        que.append((to, c + cost, time + t))

if ans == float('inf'):
    print(-1)
else:
    print(ans)
0