結果

問題 No.1 道のショートカット
ユーザー roiti46roiti46
提出日時 2015-02-15 23:26:38
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 613 bytes
コンパイル時間 793 ms
コンパイル使用メモリ 6,788 KB
実行使用メモリ 136,680 KB
最終ジャッジ日時 2023-09-22 11:58:14
合計ジャッジ時間 14,564 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
5,880 KB
testcase_01 AC 10 ms
5,852 KB
testcase_02 AC 10 ms
5,936 KB
testcase_03 AC 11 ms
5,856 KB
testcase_04 WA -
testcase_05 AC 11 ms
5,932 KB
testcase_06 AC 11 ms
5,848 KB
testcase_07 AC 10 ms
6,000 KB
testcase_08 AC 26 ms
6,244 KB
testcase_09 AC 14 ms
6,064 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 11 ms
5,988 KB
testcase_16 WA -
testcase_17 AC 10 ms
5,876 KB
testcase_18 AC 12 ms
6,180 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 12 ms
6,096 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 59 ms
7,784 KB
testcase_26 WA -
testcase_27 TLE -
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 #

inf = 10**10
def get_paths(n,path,cost):
    if n == N-1: return [path]
    res = []
    for i in xrange(n+1,N):
        if cost + G[n][i][0] > C: continue
        res += get_paths(i,path+[i],cost+G[n][i][0])
    return res
    
N,C,V = [int(raw_input()) for i in range(3)]
S,T,Y,M = [map(int,raw_input().split()) for i in range(4)]
G = [[[inf,inf] for i in xrange(N)] for j in xrange(N)]
for i in xrange(V): G[S[i]-1][T[i]-1] = [Y[i],M[i]]

paths = get_paths(0,[0],0)
ans = inf if len(paths) > 0 else -1
for path in paths:
    ans = min(ans, sum(G[path[i]][path[i+1]][1] for i in xrange(len(path)-1)))
print ans
0