import std.algorithm, std.array, std.container, std.range, std.bitmanip; import std.numeric, std.math, std.bigint, std.random; import std.string, std.conv, std.stdio, std.typecons; struct path { int e; int y; int m; } void main() { auto n = readln.chomp.to!int; auto c = readln.chomp.to!int; auto v = readln.chomp.to!int; auto si = readln.split.map!(to!int).map!("a - 1"); auto ti = readln.split.map!(to!int).map!("a - 1"); auto yi = readln.split.map!(to!int); auto mi = readln.split.map!(to!int); auto tij = new int[][](n); auto yij = new int[][](n); auto mij = new int[][](n); foreach (i; 0..v) { tij[si[i]] ~= ti[i]; yij[si[i]] ~= yi[i]; mij[si[i]] ~= mi[i]; } auto min = int.max; auto stack = SList!path(); stack.insertFront(path(0, 0, 0)); while (!stack.empty) { auto p = stack.front; stack.removeFront; if (p.e == n - 1) { if (p.m < min) min = p.m; continue; } foreach (i, t; tij[p.e]) { auto y = yij[p.e][i]; auto m = mij[p.e][i]; if (y == 0 || m == 0 || p.m + m > min || p.y + y > c) continue; stack.insertFront(path(t, p.y + y, p.m + m)); } } writeln(min == int.max ? -1 : min); }