結果

問題 No.1 道のショートカット
ユーザー AAAR SalmonAAAR Salmon
提出日時 2021-05-22 13:07:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 66 ms / 5,000 ms
コード長 595 bytes
コンパイル時間 295 ms
コンパイル使用メモリ 82,320 KB
実行使用メモリ 68,968 KB
最終ジャッジ日時 2024-04-18 17:37:51
合計ジャッジ時間 3,548 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
52,924 KB
testcase_01 AC 37 ms
52,932 KB
testcase_02 AC 39 ms
54,464 KB
testcase_03 AC 39 ms
53,976 KB
testcase_04 AC 44 ms
52,388 KB
testcase_05 AC 39 ms
53,360 KB
testcase_06 AC 39 ms
52,268 KB
testcase_07 AC 37 ms
52,984 KB
testcase_08 AC 56 ms
64,800 KB
testcase_09 AC 49 ms
61,664 KB
testcase_10 AC 51 ms
65,236 KB
testcase_11 AC 53 ms
64,712 KB
testcase_12 AC 64 ms
68,876 KB
testcase_13 AC 61 ms
67,672 KB
testcase_14 AC 46 ms
60,172 KB
testcase_15 AC 40 ms
53,004 KB
testcase_16 AC 46 ms
60,468 KB
testcase_17 AC 39 ms
53,416 KB
testcase_18 AC 45 ms
60,172 KB
testcase_19 AC 45 ms
60,532 KB
testcase_20 AC 47 ms
60,660 KB
testcase_21 AC 45 ms
59,416 KB
testcase_22 AC 45 ms
60,088 KB
testcase_23 AC 59 ms
66,992 KB
testcase_24 AC 51 ms
64,172 KB
testcase_25 AC 45 ms
60,840 KB
testcase_26 AC 46 ms
61,744 KB
testcase_27 AC 66 ms
68,968 KB
testcase_28 AC 39 ms
53,288 KB
testcase_29 AC 54 ms
65,136 KB
testcase_30 AC 46 ms
60,664 KB
testcase_31 AC 49 ms
62,800 KB
testcase_32 AC 52 ms
63,888 KB
testcase_33 AC 51 ms
62,644 KB
testcase_34 AC 55 ms
65,068 KB
testcase_35 AC 41 ms
55,584 KB
testcase_36 AC 53 ms
64,400 KB
testcase_37 AC 47 ms
61,532 KB
testcase_38 AC 40 ms
52,876 KB
testcase_39 AC 46 ms
61,280 KB
testcase_40 AC 41 ms
53,320 KB
testcase_41 AC 40 ms
54,048 KB
testcase_42 AC 39 ms
52,624 KB
testcase_43 AC 39 ms
52,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop, heappush


V = int(input())
C = int(input())
E = int(input())
edges = [[] for _ in range(V)]
for s, t, y, m in zip(*(map(int,input().split()) for _ in range(4))):
	edges[s - 1].append((m, y, t - 1))

INF = 1 << 60
dp = [[INF] * (C + 1) for _ in range(V)]
dp[0] = [0] * (C + 1)

q = [(0, 0, 0)]
while q:
	m, y, s = heappop(q)
	for dm, dy, t in edges[s]:
		if y + dy > C or m + dm >= dp[t][y + dy]:
			continue
		for ny in range(y + dy, C + 1):
			dp[t][ny] = min(dp[t][ny], m + dm)
		heappush(q, (m + dm, y + dy, t))

print(dp[V - 1][C] if dp[V - 1][C] != INF else -1)
0