結果
| 問題 | No.2739 Time is money |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-04-23 17:44:08 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,309 ms / 2,000 ms |
| コード長 | 1,095 bytes |
| コンパイル時間 | 401 ms |
| コンパイル使用メモリ | 82,368 KB |
| 実行使用メモリ | 159,924 KB |
| 最終ジャッジ日時 | 2024-10-15 18:20:55 |
| 合計ジャッジ時間 | 19,027 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 18 |
ソースコード
from heapq import heappop, heappush
from math import inf, isinf
import sys
def printe(*args, end="\n", **kwargs):
print(*args, end=end, file=sys.stderr, **kwargs)
def main():
N, M, X = map(int, input().split())
graph = [{} for _ in range(N)]
for _ in range(M):
u, v, C, T = map(int, input().split())
graph[u - 1][v - 1] = (C + T * X, T)
graph[v - 1][u - 1] = (C + T * X, T)
distance = [(inf, inf)] * N
distance[0] = (0, 0)
queue = [(0, 0, 0)]
while queue:
c_total, c_t, c_n = heappop(queue)
if distance[c_n][0] < c_total:
continue
for n_n, (n_total, n_t) in graph[c_n].items():
if distance[n_n][0] > c_total + n_total:
distance[n_n] = (c_total + n_total, c_t + n_t)
heappush(queue, (c_total + n_total, c_t + n_t, n_n))
if isinf(distance[N - 1][0]):
print(-1)
else:
print(distance[N - 1][1] + (distance[N - 1]
[0] - distance[N - 1][1] * X + X - 1) // X)
if __name__ == "__main__":
main()