結果

問題 No.2739 Time is money
ユーザー PNJPNJ
提出日時 2024-04-20 12:43:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,097 ms / 2,000 ms
コード長 720 bytes
コンパイル時間 317 ms
コンパイル使用メモリ 82,136 KB
実行使用メモリ 123,308 KB
最終ジャッジ日時 2024-04-20 12:44:04
合計ジャッジ時間 14,824 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
52,480 KB
testcase_01 AC 37 ms
52,736 KB
testcase_02 AC 253 ms
95,360 KB
testcase_03 AC 862 ms
112,996 KB
testcase_04 AC 227 ms
94,484 KB
testcase_05 AC 627 ms
101,740 KB
testcase_06 AC 775 ms
107,304 KB
testcase_07 AC 967 ms
120,252 KB
testcase_08 AC 1,043 ms
122,376 KB
testcase_09 AC 1,065 ms
122,980 KB
testcase_10 AC 383 ms
108,432 KB
testcase_11 AC 1,097 ms
123,308 KB
testcase_12 AC 348 ms
109,836 KB
testcase_13 AC 380 ms
109,696 KB
testcase_14 AC 358 ms
109,952 KB
testcase_15 AC 760 ms
121,180 KB
testcase_16 AC 752 ms
110,388 KB
testcase_17 AC 976 ms
121,728 KB
testcase_18 AC 983 ms
121,984 KB
testcase_19 AC 758 ms
117,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
inf = 1 << 61
def dijkstra(s, n, edge):
    dist = [inf]*n
    dist[s] = 0
    hq = [[0,s]]
    heapq.heapify(hq)
    while len(hq) > 0:
        d,i = heapq.heappop(hq)
        if dist[i] < d:
            continue
        for j,d_1 in edge[i]:
            if dist[j] > (dist[i] + d_1):
                dist[j] = dist[i] + d_1
                heapq.heappush(hq, [dist[j],j])
    return dist

N,M,X = map(int,input().split())
G = [[] for i in range(N)]
for i in range(M):
  u,v,c,t = map(int,input().split())
  d = c + t*X
  u -= 1
  v -= 1
  G[u].append((v,d))
  G[v].append((u,d))

dist = dijkstra(0,N,G)
if dist[N-1] == inf:
  print(-1)
  exit()
ans = dist[N-1] // X
if dist[N-1] % X:
  ans += 1
print(ans)
0