結果
| 問題 | No.2739 Time is money |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-04-21 13:31:56 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 908 bytes |
| 記録 | |
| コンパイル時間 | 221 ms |
| コンパイル使用メモリ | 82,112 KB |
| 実行使用メモリ | 278,960 KB |
| 最終ジャッジ日時 | 2024-10-13 12:09:47 |
| 合計ジャッジ時間 | 16,760 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 8 WA * 3 TLE * 3 -- * 4 |
ソースコード
from collections import deque,defaultdict
import heapq
N,M,X=map(int,input().split())
G=[[] for _ in range(N)]
C=defaultdict(int)
T=defaultdict(int)
for _ in range(M):
u,v,c,t=map(int,input().split())
u-=1;v-=1
G[u].append(v)
G[v].append(u)
C[(u,v)]=c
C[(v,u)]=c
T[(u,v)]=t
T[(v,u)]=t
vis=[(1<<60,1<<60,1<<60) for _ in range(N)] # t,c,m
attr=defaultdict(tuple)
hq=[]
heapq.heapify(hq)
hq.append((0,0,0,0)) # t,c,m,nxt
while hq:
t,c,m,now=heapq.heappop(hq)
vis[now]=(t,c,m)
if now==N-1:break
for nxt in G[now]:
work=0
if c+C[(now,nxt)]>m:
work=(m-c+C[(now,nxt)]+X-1)//X
if t+T[(now,nxt)]+work<vis[nxt][0] or \
t+T[(now,nxt)]+work==vis[nxt][0] and c+C[(now,nxt)]<vis[nxt][1]:
heapq.heappush(hq,((t+T[(now,nxt)]+work,c+C[(now,nxt)],m+X*work,nxt)))
if vis[N-1][0]==1<<60:print(-1)
else:print(vis[N-1][0])