結果

問題 No.2739 Time is money
ユーザー anonymouslyanonymously
提出日時 2024-04-20 10:55:08
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 915 bytes
コンパイル時間 92 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 119,680 KB
最終ジャッジ日時 2024-04-20 10:55:25
合計ジャッジ時間 14,078 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
17,948 KB
testcase_01 AC 34 ms
10,880 KB
testcase_02 AC 1,054 ms
68,864 KB
testcase_03 TLE -
testcase_04 AC 1,023 ms
66,432 KB
testcase_05 AC 1,808 ms
70,144 KB
testcase_06 TLE -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

N,M,X=map(int,input().split())
G=[{} for i in range(N)]
for j in range(M):
    u,v,c,t=map(int,input().split())
    u-=1
    v-=1
    G[u][v]=(c,t)
    G[v][u]=(c,t)

def dijkstra(s,g):
    cost=[float("inf")]*N
    prev=[None]*N
    cost[s]=0
    Q=[(0,s)]
    heapq.heapify(Q)
    while Q:
        d,v=heapq.heappop(Q)
        if d>cost[v]:
            continue
        for u in G[v]:
            c,t=G[u][v]
            #(かかる時間)=c/X+t
            money=c+X*t
            if cost[v]+money<cost[u]:
                cost[u]=cost[v]+money
                heapq.heappush(Q,(cost[u],u))
                prev[u]=v
    
    if prev[g] is None:
        return -1
    else:
        c=0
        t=0
        v=g
        u=prev[v]
        while u is not None:
            c+=G[u][v][0]
            t+=G[u][v][1]
            v=u
            u=prev[v]
        return (c+X-1)//X+t

print(dijkstra(0,N-1))
0