結果
| 問題 |
No.2739 Time is money
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-11-11 01:02:26 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 722 ms / 2,000 ms |
| コード長 | 1,049 bytes |
| コンパイル時間 | 458 ms |
| コンパイル使用メモリ | 82,036 KB |
| 実行使用メモリ | 115,732 KB |
| 最終ジャッジ日時 | 2024-11-11 01:02:42 |
| 合計ジャッジ時間 | 12,757 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 18 |
ソースコード
# https://yukicoder.me/problems/no/2739
import heapq
MAX_INT = 10 ** 18
def main():
N, M, X = map(int, input().split())
next_nodes = [[] for _ in range(N)]
for _ in range(M):
u, v, C, T = map(int, input().split())
next_nodes[u - 1].append((v - 1, X * T + C))
next_nodes[v - 1].append((u - 1, X * T + C))
fix = [MAX_INT ] * N
seen = [MAX_INT] * N
seen[0] = 0
queue = []
heapq.heappush(queue, (0, 0))
while len(queue) > 0:
cost, v = heapq.heappop(queue)
if fix[v] < MAX_INT:
continue
fix[v] = cost
for w, c in next_nodes[v]:
if fix[w] < MAX_INT:
continue
new_cost = c + cost
if seen[w] > new_cost:
seen[w] = new_cost
heapq.heappush(queue, (new_cost, w))
if fix[N - 1] == MAX_INT:
print(-1)
else:
x = fix[N - 1]
answer = x // X + (1 if x % X > 0 else 0)
print(answer)
if __name__ == "__main__":
main()