結果

問題 No.2739 Time is money
ユーザー tassei903tassei903
提出日時 2024-04-17 03:20:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 859 ms / 2,000 ms
コード長 668 bytes
コンパイル時間 277 ms
コンパイル使用メモリ 82,264 KB
実行使用メモリ 114,784 KB
最終ジャッジ日時 2024-04-17 03:20:28
合計ジャッジ時間 11,511 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
52,864 KB
testcase_01 AC 40 ms
52,608 KB
testcase_02 AC 294 ms
95,548 KB
testcase_03 AC 684 ms
106,008 KB
testcase_04 AC 261 ms
95,232 KB
testcase_05 AC 515 ms
97,432 KB
testcase_06 AC 573 ms
101,908 KB
testcase_07 AC 795 ms
113,920 KB
testcase_08 AC 768 ms
114,576 KB
testcase_09 AC 831 ms
114,504 KB
testcase_10 AC 442 ms
109,696 KB
testcase_11 AC 859 ms
114,784 KB
testcase_12 AC 439 ms
110,452 KB
testcase_13 AC 420 ms
110,836 KB
testcase_14 AC 390 ms
110,288 KB
testcase_15 AC 478 ms
112,820 KB
testcase_16 AC 419 ms
105,948 KB
testcase_17 AC 801 ms
114,392 KB
testcase_18 AC 777 ms
114,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *
INF = 10**18
def dijkstra(g, s, n):
    dist = [INF]*n
    hq = [(0, s)]
    dist[s] = 0
    while hq:
        d, v = heappop(hq)
        if dist[v]!=d:
            continue
        for to, c in g[v]:
            if dist[v] + c < dist[to]:
                dist[to] = dist[v] + c
                heappush(hq, (dist[to], to))
    return dist

n, m, x = list(map(int, input().split()))
g = [[] for _ in range(n)]

for i in range(m):
    u,v,c,t = list(map(int, input().split()))
    u -= 1
    v -= 1
    g[u].append((v,t*x+c))
    g[v].append((u,t*x+c))

dist = dijkstra(g, 0, n)
if dist[-1] == INF:
    print(-1)
else:
    print((dist[-1] + x-1)//x)
0