結果

問題 No.1 道のショートカット
ユーザー warashiwarashi
提出日時 2015-02-08 23:06:52
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
MLE  
実行時間 -
コード長 1,575 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 11,152 KB
実行使用メモリ 816,844 KB
最終ジャッジ日時 2023-09-22 11:56:48
合計ジャッジ時間 2,842 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,328 KB
testcase_01 AC 16 ms
8,436 KB
testcase_02 AC 17 ms
8,316 KB
testcase_03 AC 16 ms
8,316 KB
testcase_04 AC 16 ms
8,408 KB
testcase_05 AC 16 ms
8,364 KB
testcase_06 AC 17 ms
8,380 KB
testcase_07 AC 16 ms
8,416 KB
testcase_08 MLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
def memoize(fn):
    table = {}

    def func(*args):
        if args not in table:
            table[args] = fn(*args)
        return table[args]
    return func


class Town(object):

    def __init__(self, num):
        self.edge_forward = []
        self.edge_backward = []
        self.num = num
        self.is_start = False
        self.is_goal = False

    def append_forward(self, edge):
        self.edge_forward.append(edge)

    def append_backward(self, edge):
        self.edge_backward.append(edge)


class Edge(object):

    def __init__(self, frm, to, cost, distance):
        self.frm = frm
        self.to = to
        self.cost = cost
        self.distance = distance


@memoize
def path(town):
    if town.is_start:
        return [(0, 0)]
    p = []
    for e in town.edge_backward:
        for cost, distance in path(e.frm):
            cost += e.cost
            distance += e.distance
            p.append((cost, distance))
    return p

N = int(input())
C = int(input())
V = int(input())
S = [int(s) for s in input().split()]
T = [int(t) for t in input().split()]
Y = [int(y) for y in input().split()]
M = [int(m) for m in input().split()]

town = [Town(num) for num in range(N)]
RODE = zip(S, T, Y, M)
for s, t, y, m in RODE:
    town[s - 1].append_forward(Edge(town[s - 1], town[t - 1], y, m))
    town[t - 1].append_backward(Edge(town[s - 1], town[t - 1], y, m))
town[0].is_start = True
town[-1].is_goal = True

ways = path(town[-1])
p = [d for c, d in ways if c <= C]
if len(p) == 0:
    print(-1)
else:
    print(min(p))
0