結果

問題 No.1 道のショートカット
コンテスト
ユーザー roiti46
提出日時 2015-02-15 23:26:38
言語 PyPy2
(7.3.15)
結果
WA  
実行時間 -
コード長 613 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 129 ms
コンパイル使用メモリ 77,504 KB
最終ジャッジ日時 2025-12-03 13:54:09
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1
other AC * 16 WA * 24
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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