結果

問題 No.1 道のショートカット
ユーザー kamiyomokikanukamiyomokikanu
提出日時 2019-08-16 23:58:29
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,504 bytes
コンパイル時間 70 ms
コンパイル使用メモリ 10,808 KB
実行使用メモリ 13,572 KB
最終ジャッジ日時 2023-09-22 13:33:51
合計ジャッジ時間 8,516 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,648 KB
testcase_01 AC 19 ms
8,776 KB
testcase_02 AC 21 ms
8,684 KB
testcase_03 AC 19 ms
8,652 KB
testcase_04 AC 19 ms
8,780 KB
testcase_05 AC 21 ms
8,804 KB
testcase_06 AC 19 ms
8,680 KB
testcase_07 AC 19 ms
8,744 KB
testcase_08 AC 1,535 ms
9,052 KB
testcase_09 TLE -
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 #

from collections import deque

N=int(input())
C=int(input())
V=int(input())
S=list(map(int, input().split()))
T=list(map(int, input().split()))
Y=list(map(int, input().split()))
M=list(map(int, input().split()))

#print(S)
#print(T)
#print(Y)
#print(M)

p=[]
for i in range(V):
    p.append([S[i],T[i],Y[i],M[i]])

#print (p)

l=[[] for i in range(N+1)]
lw=[[] for i in range(N+1)]
lt=[[] for i in range(N+1)]
for pi in p:
    l[pi[0]].append(pi[1])
    l[pi[1]].append(pi[0])
    lw[pi[0]].append(pi[2])
    lw[pi[1]].append(pi[2])
    lt[pi[0]].append(pi[3])
    lt[pi[1]].append(pi[3])

#print(l)
#print(lw)
#print(lt)

queue=deque([1])
data=[-1 for i in range(N+1)]
dp=[[-1 for i in range(C+1)] for j in range(N+1)]
dp[1][0]=0

while len(queue) > 0:
    n=queue.popleft()
    data[n]=-1
    #print (n)
    f=False
    for i in range(len(l[n])):
        nt=l[n][i]
        ntw=lw[n][i]
        ntt=lt[n][i]
        #print(str(nt)+","+str(ntw)+","+str(ntt))
        for j in range(C+1):
            if dp[n][j]!=-1:
                tw=j+ntw
                tt=dp[n][j]+ntt
                #print(str(tw)+"-"+str(tt))
                if tw>C:continue
                if dp[nt][tw]==-1 or tt<dp[nt][tw]:
                    dp[nt][tw]=tt
                    f=True
        if f and data[nt]==-1:
            queue.append(nt)
            data[nt]=1
#print(dp)

ans=-1
for dpi in dp[N]:
    if(dpi!=-1):
        if(ans==-1):
            ans=dpi
        else:
            ans=min(ans,dpi)

print (str(ans))
0