結果

問題 No.1 道のショートカット
ユーザー sue_charo
提出日時 2017-06-01 19:09:16
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
MLE  
実行時間 -
コード長 1,413 bytes
コンパイル時間 100 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 784,364 KB
最終ジャッジ日時 2024-07-08 04:52:37
合計ジャッジ時間 7,095 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 7 MLE * 1 -- * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8
import array, bisect, collections, copy, heapq, itertools, math, random, re, string, sys, time

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7


def II(): return int(input())
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LINE)]
def IDI(): return {key: value for key, value in ILI()}


def read():
    N = II()
    C = II()
    V = II()
    S = ILI()
    T = ILI()
    Y = ILI()
    M = ILI()
    return (N, C, V, S, T, Y, M)


def solve(N, C, V, S, T, Y, M):
    edge = collections.defaultdict(list)
    for i in range(V):
        edge[S[i]].append((T[i], Y[i], M[i]))
    # vertex list. 0-indexed. has all (time, cost).
    l_vertex = [[] for __ in range(N)]
    l_vertex[0].append((0, 0))
    for i in range(N):
        now_ver = l_vertex[i]
        for v in now_ver:
            for e in edge[i + 1]:
                next_ver = e[0] - 1
                next_cost = v[1] + e[1]
                next_time = v[0] + e[2]
                if next_cost > C:
                    continue
                else:
                    l_vertex[next_ver].append((next_time, next_cost))

    ans = 0
    if len(l_vertex[N - 1]) == 0:
        ans = -1
    else:
        l_ans = sorted(l_vertex[N - 1])
        ans = l_ans[0][0]

    return ans


def main():
    params = read()
    print(solve(*params))


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