結果

問題 No.1 道のショートカット
ユーザー cologne
提出日時 2022-01-20 12:11:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 59 ms / 5,000 ms
コード長 796 bytes
コンパイル時間 207 ms
コンパイル使用メモリ 82,236 KB
実行使用メモリ 64,512 KB
最終ジャッジ日時 2024-11-23 15:01:46
合計ジャッジ時間 3,745 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    C = int(input())
    V = int(input())
    *S, = map(int, input().split())
    *T, = map(int, input().split())
    *Y, = map(int, input().split())
    *M, = map(int, input().split())

    adj = [[] for i in range(N)]
    for i in range(V):
        adj[S[i]-1].append((T[i]-1, Y[i], M[i]))

    vis = [[False]*N for i in range(C+1)]
    Q = [(0, C, 0)]

    while len(Q) != 0:
        d, c, v = heapq.heappop(Q)

        if vis[c][v]:
            continue
        vis[c][v] = True

        if v == N-1:
            print(d)
            return

        for u, nc, nd in adj[v]:
            if c >= nc:
                heapq.heappush(Q, (d+nd, c-nc, u))

    print(-1)


if __name__ == '__main__':
    main()
0