結果

問題 No.2739 Time is money
ユーザー Ekiben542Ekiben542
提出日時 2024-04-20 23:08:23
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 943 bytes
コンパイル時間 304 ms
コンパイル使用メモリ 82,136 KB
実行使用メモリ 183,092 KB
最終ジャッジ日時 2024-04-20 23:08:42
合計ジャッジ時間 12,942 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
54,220 KB
testcase_01 AC 42 ms
53,236 KB
testcase_02 AC 243 ms
116,056 KB
testcase_03 WA -
testcase_04 AC 227 ms
116,744 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 482 ms
152,332 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
import math  

def dijkstra(graph, start, end, X):
    pq = [(0, start)]
    visited = set()
    while pq:
        time, node = heapq.heappop(pq)
        if node in visited:
            continue
        visited.add(node)
        if node == end:
            return math.ceil(time)  
        for neighbor, cost, travel_time in graph[node]:
            if neighbor not in visited:
                total_time = travel_time + math.ceil(cost / X)
                heapq.heappush(pq, (time + total_time, neighbor))
    return -1

def solve(N, M, X, roads):
    graph = {i: [] for i in range(1, N+1)}
    for u, v, C, T in roads:
        graph[u].append((v, C, T))
        graph[v].append((u, C, T))  
    min_time = dijkstra(graph, 1, N, X)
    return min_time

N, M, X = map(int, input().split())
roads = [tuple(map(int, input().split())) for _ in range(M)]

min_time = solve(N, M, X, roads)
print(min_time - 1 if min_time != -1 else -1)
0