結果

問題 No.2739 Time is money
ユーザー mkawa2mkawa2
提出日時 2024-04-20 14:04:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,163 ms / 2,000 ms
コード長 1,472 bytes
コンパイル時間 143 ms
コンパイル使用メモリ 82,396 KB
実行使用メモリ 158,752 KB
最終ジャッジ日時 2024-04-20 14:04:50
合計ジャッジ時間 15,207 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
54,232 KB
testcase_01 AC 35 ms
53,464 KB
testcase_02 AC 238 ms
113,232 KB
testcase_03 AC 965 ms
143,240 KB
testcase_04 AC 249 ms
112,584 KB
testcase_05 AC 664 ms
124,396 KB
testcase_06 AC 804 ms
137,752 KB
testcase_07 AC 1,123 ms
156,244 KB
testcase_08 AC 1,162 ms
158,056 KB
testcase_09 AC 1,163 ms
158,752 KB
testcase_10 AC 400 ms
140,624 KB
testcase_11 AC 1,159 ms
158,672 KB
testcase_12 AC 386 ms
143,584 KB
testcase_13 AC 383 ms
143,360 KB
testcase_14 AC 401 ms
133,424 KB
testcase_15 AC 758 ms
155,576 KB
testcase_16 AC 773 ms
144,816 KB
testcase_17 AC 1,106 ms
157,508 KB
testcase_18 AC 1,104 ms
151,884 KB
testcase_19 AC 778 ms
140,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
# sys.set_int_max_str_digits(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
# inf = -1-(-1 << 31)
inf = -1-(-1 << 62)

# md = 10**9+7
md = 998244353

from heapq import *

def dijkstra(to, root=0):
    n = len(to)
    dist = [(inf, inf)]*n
    dist[root] = (0, 0)
    hp = [(0, 0, root)]
    while hp:
        d, m, u = heappop(hp)
        if (d, m) > dist[u]: continue
        for v, c, t in to[u]:
            nd = d+t+(m+c)//x
            nm = (m+c)%x
            if dist[v] <= (nd, nm): continue
            dist[v] = (nd, nm)
            heappush(hp, (nd, nm, v))

    return dist

n, m, x = LI()
to = [[] for _ in range(n)]
for _ in range(m):
    u, v, c, t = LI()
    u, v = u-1, v-1
    to[u].append((v, c, t))
    to[v].append((u, c, t))

dist=dijkstra(to)
ans=dist[-1][0]
if ans==inf:
    print(-1)
else:
    if dist[-1][1]:ans+=1
    print(ans)
0