結果
問題 | No.2739 Time is money |
ユーザー | rlangevin |
提出日時 | 2024-04-20 14:20:11 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 734 ms / 2,000 ms |
コード長 | 1,170 bytes |
コンパイル時間 | 190 ms |
コンパイル使用メモリ | 82,580 KB |
実行使用メモリ | 119,632 KB |
最終ジャッジ日時 | 2024-04-20 14:20:24 |
合計ジャッジ時間 | 9,895 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
52,872 KB |
testcase_01 | AC | 41 ms
53,540 KB |
testcase_02 | AC | 209 ms
101,912 KB |
testcase_03 | AC | 455 ms
107,024 KB |
testcase_04 | AC | 202 ms
100,524 KB |
testcase_05 | AC | 352 ms
97,424 KB |
testcase_06 | AC | 488 ms
103,308 KB |
testcase_07 | AC | 653 ms
117,764 KB |
testcase_08 | AC | 454 ms
116,848 KB |
testcase_09 | AC | 493 ms
116,380 KB |
testcase_10 | AC | 362 ms
110,292 KB |
testcase_11 | AC | 734 ms
119,632 KB |
testcase_12 | AC | 450 ms
117,832 KB |
testcase_13 | AC | 467 ms
117,760 KB |
testcase_14 | AC | 427 ms
117,944 KB |
testcase_15 | AC | 318 ms
113,564 KB |
testcase_16 | AC | 192 ms
105,336 KB |
testcase_17 | AC | 662 ms
118,000 KB |
testcase_18 | AC | 698 ms
117,700 KB |
testcase_19 | AC | 385 ms
109,380 KB |
ソースコード
import sys input = sys.stdin.readline from heapq import heappush, heappop inf = float('inf') def dijkstra(s, g, G): # ゴールがない場合はg=-1とする。 N = len(G) def cost(v, m): return v * N + m dist = [inf] * N mindist = [inf] * N seen = [False] * N Q = [cost(0, s)] while Q: c, m = divmod(heappop(Q), N) if seen[m]: continue seen[m] = True dist[m] = c if m == g: return dist #------heapをアップデートする。-------- for u, C in G[m]: if seen[u]: continue newdist = dist[m] + C #------------------------------------ if newdist >= mindist[u]: continue mindist[u] = newdist heappush(Q, cost(newdist, u)) return dist N, M, X = map(int, input().split()) G = [[] for i in range(N)] for i in range(M): u, v, c, t = map(int, input().split()) u, v = u - 1, v - 1 G[u].append((v, t * X + c)) G[v].append((u, t * X + c)) D = dijkstra(0, N - 1, G) print((D[-1]+X-1)//X) if D[-1] != inf else print("-1")