結果

問題 No.1 道のショートカット
ユーザー sue_charosue_charo
提出日時 2017-06-01 19:38:33
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 109 ms / 5,000 ms
コード長 1,489 bytes
コンパイル時間 506 ms
コンパイル使用メモリ 11,080 KB
実行使用メモリ 11,244 KB
最終ジャッジ日時 2023-09-27 22:06:18
合計ジャッジ時間 3,755 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
10,112 KB
testcase_01 AC 28 ms
10,148 KB
testcase_02 AC 29 ms
10,136 KB
testcase_03 AC 27 ms
10,228 KB
testcase_04 AC 27 ms
10,116 KB
testcase_05 AC 27 ms
10,104 KB
testcase_06 AC 28 ms
10,144 KB
testcase_07 AC 27 ms
10,124 KB
testcase_08 AC 32 ms
10,596 KB
testcase_09 AC 28 ms
10,268 KB
testcase_10 AC 33 ms
10,468 KB
testcase_11 AC 45 ms
10,616 KB
testcase_12 AC 62 ms
11,244 KB
testcase_13 AC 60 ms
11,240 KB
testcase_14 AC 27 ms
10,180 KB
testcase_15 AC 28 ms
10,112 KB
testcase_16 AC 28 ms
10,232 KB
testcase_17 AC 27 ms
10,128 KB
testcase_18 AC 26 ms
10,184 KB
testcase_19 AC 27 ms
10,124 KB
testcase_20 AC 32 ms
10,284 KB
testcase_21 AC 28 ms
10,212 KB
testcase_22 AC 27 ms
10,164 KB
testcase_23 AC 107 ms
10,900 KB
testcase_24 AC 109 ms
11,068 KB
testcase_25 AC 34 ms
10,380 KB
testcase_26 AC 30 ms
10,256 KB
testcase_27 AC 73 ms
11,068 KB
testcase_28 AC 26 ms
10,236 KB
testcase_29 AC 35 ms
10,300 KB
testcase_30 AC 27 ms
10,208 KB
testcase_31 AC 31 ms
10,280 KB
testcase_32 AC 37 ms
10,624 KB
testcase_33 AC 31 ms
10,300 KB
testcase_34 AC 67 ms
10,716 KB
testcase_35 AC 27 ms
10,240 KB
testcase_36 AC 30 ms
10,284 KB
testcase_37 AC 27 ms
10,308 KB
testcase_38 AC 25 ms
10,160 KB
testcase_39 AC 27 ms
10,148 KB
testcase_40 AC 28 ms
10,112 KB
testcase_41 AC 26 ms
10,156 KB
testcase_42 AC 25 ms
10,116 KB
testcase_43 AC 26 ms
10,144 KB
権限があれば一括ダウンロードができます

ソースコード

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] - 1].append((T[i] - 1, Y[i], M[i]))
    dp = [[INF] * (C + 1) for _ in range(N)]
    dp[0][C] = 0
    queue = list()
    heapq.heappush(queue, (0, C))
    while len(queue) > 0:
        now_ver, now_cost = heapq.heappop(queue)
        now_time = dp[now_ver][now_cost]
        for next_ver, next_cost, next_time in edge[now_ver]:
            if (now_cost - next_cost) < 0:
                continue
            else:
                if dp[next_ver][now_cost - next_cost] > (now_time + next_time):
                    dp[next_ver][now_cost - next_cost] = now_time + next_time
                    heapq.heappush(queue, (next_ver, now_cost - next_cost))

    ans = INF
    for m in dp[N - 1]:
        ans = min(ans, m)

    if ans == INF:
        ans = -1

    return ans


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


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