結果

問題 No.1 道のショートカット
ユーザー kamiyomokikanukamiyomokikanu
提出日時 2019-08-16 23:58:56
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,504 bytes
コンパイル時間 302 ms
コンパイル使用メモリ 86,648 KB
実行使用メモリ 78,724 KB
最終ジャッジ日時 2023-09-22 13:34:21
合計ジャッジ時間 8,210 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 100 ms
76,796 KB
testcase_01 AC 101 ms
76,688 KB
testcase_02 AC 101 ms
76,888 KB
testcase_03 AC 94 ms
71,704 KB
testcase_04 AC 93 ms
71,624 KB
testcase_05 AC 103 ms
76,700 KB
testcase_06 AC 92 ms
71,736 KB
testcase_07 AC 99 ms
76,672 KB
testcase_08 AC 184 ms
78,540 KB
testcase_09 AC 532 ms
77,744 KB
testcase_10 AC 142 ms
77,724 KB
testcase_11 AC 156 ms
78,592 KB
testcase_12 AC 317 ms
78,540 KB
testcase_13 AC 363 ms
78,412 KB
testcase_14 AC 115 ms
77,300 KB
testcase_15 AC 98 ms
76,312 KB
testcase_16 WA -
testcase_17 AC 98 ms
76,076 KB
testcase_18 AC 116 ms
77,500 KB
testcase_19 AC 129 ms
77,520 KB
testcase_20 AC 133 ms
77,836 KB
testcase_21 WA -
testcase_22 AC 121 ms
77,304 KB
testcase_23 AC 179 ms
78,164 KB
testcase_24 AC 182 ms
78,288 KB
testcase_25 AC 140 ms
77,852 KB
testcase_26 AC 131 ms
77,604 KB
testcase_27 AC 183 ms
78,724 KB
testcase_28 AC 108 ms
77,180 KB
testcase_29 AC 130 ms
77,784 KB
testcase_30 AC 112 ms
77,472 KB
testcase_31 AC 113 ms
77,352 KB
testcase_32 AC 174 ms
77,644 KB
testcase_33 AC 137 ms
77,560 KB
testcase_34 AC 185 ms
78,024 KB
testcase_35 AC 116 ms
77,556 KB
testcase_36 AC 126 ms
77,620 KB
testcase_37 WA -
testcase_38 AC 105 ms
77,284 KB
testcase_39 WA -
testcase_40 AC 114 ms
77,508 KB
testcase_41 AC 107 ms
77,380 KB
testcase_42 AC 93 ms
71,552 KB
testcase_43 AC 99 ms
76,264 KB
権限があれば一括ダウンロードができます

ソースコード

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