結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
54,356 KB
testcase_01 AC 35 ms
54,100 KB
testcase_02 AC 271 ms
114,288 KB
testcase_03 AC 618 ms
146,076 KB
testcase_04 AC 233 ms
117,148 KB
testcase_05 AC 446 ms
125,244 KB
testcase_06 AC 722 ms
149,720 KB
testcase_07 AC 887 ms
171,212 KB
testcase_08 AC 625 ms
156,212 KB
testcase_09 AC 695 ms
159,688 KB
testcase_10 AC 472 ms
152,352 KB
testcase_11 AC 1,088 ms
181,688 KB
testcase_12 AC 590 ms
182,360 KB
testcase_13 AC 555 ms
181,800 KB
testcase_14 WA -
testcase_15 AC 528 ms
162,080 KB
testcase_16 AC 297 ms
137,412 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 738 ms
162,184 KB
権限があれば一括ダウンロードができます

ソースコード

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 time
        for neighbor, cost, travel_time in graph[node]:
            if neighbor not in visited:
                total_time = travel_time + 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)
floor_time = math.ceil(min_time)
print(floor_time if min_time != -1 else -1)
0