結果

問題 No.1 道のショートカット
ユーザー 双六双六
提出日時 2020-07-25 23:28:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 240 ms / 5,000 ms
コード長 1,336 bytes
コンパイル時間 449 ms
コンパイル使用メモリ 87,096 KB
実行使用メモリ 96,128 KB
最終ジャッジ日時 2023-09-27 22:31:59
合計ジャッジ時間 7,812 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
71,764 KB
testcase_01 AC 89 ms
71,852 KB
testcase_02 AC 86 ms
71,608 KB
testcase_03 AC 97 ms
77,784 KB
testcase_04 AC 85 ms
71,568 KB
testcase_05 AC 89 ms
71,680 KB
testcase_06 AC 96 ms
77,636 KB
testcase_07 AC 98 ms
77,584 KB
testcase_08 AC 172 ms
87,012 KB
testcase_09 AC 116 ms
79,068 KB
testcase_10 AC 163 ms
89,516 KB
testcase_11 AC 203 ms
93,884 KB
testcase_12 AC 240 ms
90,120 KB
testcase_13 AC 216 ms
89,636 KB
testcase_14 AC 98 ms
77,504 KB
testcase_15 AC 83 ms
71,800 KB
testcase_16 AC 105 ms
78,724 KB
testcase_17 AC 94 ms
77,380 KB
testcase_18 AC 100 ms
78,452 KB
testcase_19 AC 104 ms
78,240 KB
testcase_20 AC 152 ms
83,640 KB
testcase_21 AC 114 ms
78,088 KB
testcase_22 AC 103 ms
78,132 KB
testcase_23 AC 218 ms
96,128 KB
testcase_24 AC 212 ms
92,060 KB
testcase_25 AC 161 ms
83,428 KB
testcase_26 AC 134 ms
80,984 KB
testcase_27 AC 213 ms
91,772 KB
testcase_28 AC 96 ms
77,712 KB
testcase_29 AC 164 ms
88,932 KB
testcase_30 AC 111 ms
78,088 KB
testcase_31 AC 141 ms
86,288 KB
testcase_32 AC 171 ms
85,172 KB
testcase_33 AC 156 ms
84,400 KB
testcase_34 AC 205 ms
87,928 KB
testcase_35 AC 121 ms
84,580 KB
testcase_36 AC 150 ms
88,512 KB
testcase_37 AC 115 ms
78,180 KB
testcase_38 AC 102 ms
77,784 KB
testcase_39 AC 102 ms
77,696 KB
testcase_40 AC 109 ms
79,036 KB
testcase_41 AC 103 ms
77,972 KB
testcase_42 AC 94 ms
77,532 KB
testcase_43 AC 87 ms
71,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
from heapq import heappop, heappush
INF = float('inf')

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

class Graph(object):
	def __init__(self):
		self.graph = defaultdict(list)

	def __len__(self):
		return len(self.graph)

	def add_edge(self, a, b, w):
		self.graph[a].append((b, w))

class Dijkstra(object):
	def __init__(self, graph, s):
		self.g = graph.graph
		self.dist = defaultdict(lambda: INF); self.dist[s] = 0
		self.Q = []
		heappush(self.Q, (self.dist[s], s))
		while self.Q:
			dist_u, u = heappop(self.Q)
			if self.dist[u] < dist_u:
				continue
			for v, w in self.g[u]:
				alt = dist_u + w
				if self.dist[v] > alt:
					self.dist[v] = alt
					heappush(self.Q, (alt, v))

#処理内容
def main():
	N = int(input())
	C = int(input())
	V = int(input())
	S = getlist()
	T = getlist()
	Y = getlist()
	M = getlist()
	G = Graph()
	for i in range(V):
		s, t, cost, w = S[i], T[i], Y[i], M[i]
		s -= 1; t -= 1
		for j in range(301):
			if j >= cost:
				G.add_edge(301 * s + j, 301 * t + j - cost, w)

	D = Dijkstra(G, C)
	dist = D.dist

	ans = INF
	for i in range(301):
		ans = min(ans, dist[301 * (N - 1) + i])

	if ans == INF:
		print(-1)
	else:
		print(ans)





if __name__ == '__main__':
	main()
0