import strutils, sequtils, future const INF = 987654321 type Route = object to: int cost: int time: int proc newRoute(): Route = Route(to: 0, cost: 0, time: 0) proc newRoute(to, cost, time: int): Route = Route(to: to, cost: cost, time: time) var N = stdin.readLine.parseInt C = stdin.readLine.parseInt V = stdin.readLine.parseInt S = stdin.readLine.split.map((x: string) => parseInt(x) - 1) T = stdin.readLine.split.map((x: string) => parseInt(x) - 1) Y = stdin.readLine.split.map(parseInt) M = stdin.readLine.split.map(parseInt) routes = newSeqWith(N, newSeqWith(0, newRoute())) dp = newSeqWith(N, newSeqWith(C+1, INF)) for i in 0.. C: continue dp[route.to][ncost] = min(dp[route.to][ncost], dp[v][cost] + route.time); var res = min(dp[N-1]) if res == INF: res = -1 echo res