結果
問題 | No.2739 Time is money |
ユーザー | anonymously |
提出日時 | 2024-04-20 10:55:28 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,425 ms / 2,000 ms |
コード長 | 915 bytes |
コンパイル時間 | 356 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 151,304 KB |
最終ジャッジ日時 | 2024-04-20 10:55:47 |
合計ジャッジ時間 | 18,444 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
53,248 KB |
testcase_01 | AC | 42 ms
52,736 KB |
testcase_02 | AC | 399 ms
116,564 KB |
testcase_03 | AC | 1,232 ms
130,028 KB |
testcase_04 | AC | 333 ms
111,456 KB |
testcase_05 | AC | 882 ms
111,808 KB |
testcase_06 | AC | 976 ms
114,104 KB |
testcase_07 | AC | 1,324 ms
151,304 KB |
testcase_08 | AC | 1,401 ms
150,884 KB |
testcase_09 | AC | 1,425 ms
149,564 KB |
testcase_10 | AC | 592 ms
141,388 KB |
testcase_11 | AC | 1,393 ms
149,864 KB |
testcase_12 | AC | 678 ms
148,380 KB |
testcase_13 | AC | 647 ms
148,172 KB |
testcase_14 | AC | 662 ms
148,988 KB |
testcase_15 | AC | 536 ms
139,088 KB |
testcase_16 | AC | 556 ms
132,644 KB |
testcase_17 | AC | 1,316 ms
146,472 KB |
testcase_18 | AC | 1,333 ms
146,388 KB |
testcase_19 | AC | 803 ms
137,972 KB |
ソースコード
import heapq N,M,X=map(int,input().split()) G=[{} for i in range(N)] for j in range(M): u,v,c,t=map(int,input().split()) u-=1 v-=1 G[u][v]=(c,t) G[v][u]=(c,t) def dijkstra(s,g): cost=[float("inf")]*N prev=[None]*N cost[s]=0 Q=[(0,s)] heapq.heapify(Q) while Q: d,v=heapq.heappop(Q) if d>cost[v]: continue for u in G[v]: c,t=G[u][v] #(かかる時間)=c/X+t money=c+X*t if cost[v]+money<cost[u]: cost[u]=cost[v]+money heapq.heappush(Q,(cost[u],u)) prev[u]=v if prev[g] is None: return -1 else: c=0 t=0 v=g u=prev[v] while u is not None: c+=G[u][v][0] t+=G[u][v][1] v=u u=prev[v] return (c+X-1)//X+t print(dijkstra(0,N-1))