結果

問題 No.2739 Time is money
ユーザー Ekiben542Ekiben542
提出日時 2024-04-20 23:11:32
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 920 bytes
コンパイル時間 137 ms
コンパイル使用メモリ 82,028 KB
実行使用メモリ 141,960 KB
最終ジャッジ日時 2024-04-20 23:11:45
合計ジャッジ時間 11,060 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,648 KB
testcase_01 AC 37 ms
52,736 KB
testcase_02 AC 217 ms
99,748 KB
testcase_03 WA -
testcase_04 AC 215 ms
102,580 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 367 ms
124,652 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

def min_time_to_reach(N, M, X, roads):
    graph = [[] for _ in range(N + 1)]
    for u, v, C, T in roads:
        work_time = C // X + (1 if C % X != 0 else 0)  
        graph[u].append((v, work_time + T))
        graph[v].append((u, work_time + T))  
    distances = [float('inf')] * (N + 1)
    distances[1] = 0  
    queue = [(0, 1)]  

    while queue:
        total_time, u = heapq.heappop(queue)
        if total_time > distances[u]:
            continue
        for v, time in graph[u]:
            if distances[u] + time < distances[v]:
                distances[v] = distances[u] + time
                heapq.heappush(queue, (distances[v], v))
    return distances[N] if distances[N] != float('inf') else -1
N, M, X = map(int, input().split())
roads = [tuple(map(int, input().split())) for _ in range(M)]

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