let n = Int(readLine()!)! let c = Int(readLine()!)! let v = Int(readLine()!)! let s=readLine()!.split(separator:" ").map({Int($0)!}) let t=readLine()!.split(separator:" ").map({Int($0)!}) let y=readLine()!.split(separator:" ").map({Int($0)!}) let m=readLine()!.split(separator:" ").map({Int($0)!}) var br=[Int:[(Int,Int,Int)]]() for i in 0.. Int { let start=0 var queue = ArraySlice<(Int,Int,Int,Set)>() //node,time,cost,explored queue.append((start, 0,0,Set())) var mintime = -1 while let (curnode, time, cost,explored) = queue.popFirst() { if let branches=br[curnode] { for (nextnode,timeplus,costplus) in branches { if !explored.contains(nextnode) { let newcost=cost+costplus if newcost <= c { let newtime=time+timeplus if nextnode==n-1 { //print("first goal!!") //return newtime if mintime == -1 { mintime=newtime } else { mintime = min(mintime,newtime) } } var newexplored=explored newexplored.insert(nextnode) queue.append((nextnode,newtime,newcost,newexplored)) } } } } } return mintime } print(bfs())