結果

問題 No.1 道のショートカット
ユーザー ayaoniayaoni
提出日時 2021-08-16 02:01:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 189 ms / 5,000 ms
コード長 2,018 bytes
コンパイル時間 273 ms
コンパイル使用メモリ 82,496 KB
実行使用メモリ 87,944 KB
最終ジャッジ日時 2024-04-17 04:59:18
合計ジャッジ時間 4,910 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,248 KB
testcase_01 AC 41 ms
52,864 KB
testcase_02 AC 40 ms
52,992 KB
testcase_03 AC 40 ms
53,120 KB
testcase_04 AC 41 ms
52,480 KB
testcase_05 AC 39 ms
52,736 KB
testcase_06 AC 40 ms
53,120 KB
testcase_07 AC 39 ms
52,992 KB
testcase_08 AC 127 ms
84,624 KB
testcase_09 AC 67 ms
73,216 KB
testcase_10 AC 107 ms
78,916 KB
testcase_11 AC 125 ms
80,768 KB
testcase_12 AC 189 ms
87,944 KB
testcase_13 AC 159 ms
86,632 KB
testcase_14 AC 49 ms
62,848 KB
testcase_15 AC 42 ms
58,240 KB
testcase_16 AC 54 ms
66,176 KB
testcase_17 AC 44 ms
58,624 KB
testcase_18 AC 51 ms
62,848 KB
testcase_19 AC 50 ms
63,872 KB
testcase_20 AC 98 ms
78,336 KB
testcase_21 AC 61 ms
69,632 KB
testcase_22 AC 50 ms
64,120 KB
testcase_23 AC 137 ms
84,144 KB
testcase_24 AC 150 ms
86,300 KB
testcase_25 AC 103 ms
79,616 KB
testcase_26 AC 93 ms
78,592 KB
testcase_27 AC 132 ms
83,736 KB
testcase_28 AC 46 ms
61,312 KB
testcase_29 AC 84 ms
77,696 KB
testcase_30 AC 51 ms
64,384 KB
testcase_31 AC 65 ms
70,784 KB
testcase_32 AC 121 ms
82,176 KB
testcase_33 AC 91 ms
80,384 KB
testcase_34 AC 139 ms
82,560 KB
testcase_35 AC 51 ms
63,360 KB
testcase_36 AC 70 ms
72,448 KB
testcase_37 AC 52 ms
64,000 KB
testcase_38 AC 49 ms
62,336 KB
testcase_39 AC 51 ms
64,256 KB
testcase_40 AC 54 ms
63,744 KB
testcase_41 AC 46 ms
60,288 KB
testcase_42 AC 40 ms
52,736 KB
testcase_43 AC 43 ms
58,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,heapq
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())


class Dijkstra_list():  # 1-based
    def __init__(self,N):
        self.N = N
        self.edges = [[] for _ in range(N+1)]

    def add(self,u,v,d,directed=False):
        if directed is False:  # 無向グラフの場合
            self.edges[u].append((v,d))
            self.edges[v].append((u,d))
        else:  # 有向グラフの場合
            self.edges[u].append((v,d))

    def delete(self,u,v):
        self.edges[u] = [_ for _ in self.edges[u] if _[0] != v]
        self.edges[v] = [_ for _ in self.edges[v] if _[0] != u]

    def search(self,s):  # sから各頂点までの最短距離
        inf = 10**18
        dist = [inf]*(self.N+1)
        # prev = [-1]*(self.N+1)
        dist[s] = 0
        q = []
        heapq.heappush(q,(0,s))
        flag = [0]*(self.N+1)
        while q:
            d,u = heapq.heappop(q)
            if flag[u]:
                continue
            flag[u] = 1

            for v,dd in self.edges[u]:
                if flag[v]:
                    continue
                new_d = d + dd
                if dist[v] > new_d:
                    dist[v] = new_d
                    heapq.heappush(q,(new_d,v))
                    # prev[v] = u
        return dist  # return dist,prev


N,C,V = I(),I(),I()
S,T,Y,M = LI(),LI(),LI(),LI()

Di = Dijkstra_list(N*(C+1))
for s,t,y,m in zip(S,T,Y,M):
    s -= 1
    t -= 1
    for c in range(y,C+1):
        Di.add((C+1)*s+c,(C+1)*t+(c-y),m,directed=True)

dist = Di.search(C)
ans = 10**18
for c in range(C+1):
    ans = min(ans,dist[(N-1)*(C+1)+c])

if ans == 10**18:
    ans = -1

print(ans)
0