use std::collections::VecDeque; const INF: usize = 1usize << 60; fn main() { let mut n = String::new(); std::io::stdin().read_line(&mut n).ok(); let n: usize = n.trim().parse().unwrap(); let mut c = String::new(); std::io::stdin().read_line(&mut c).ok(); let c: usize = c.trim().parse().unwrap(); let mut v = String::new(); std::io::stdin().read_line(&mut v).ok(); let v: usize = v.trim().parse().unwrap(); let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); let s: Vec = s.trim().split_whitespace().map(|s| s.parse::().unwrap()-1).collect(); let mut t = String::new(); std::io::stdin().read_line(&mut t).ok(); let t: Vec = t.trim().split_whitespace().map(|s| s.parse::().unwrap()-1).collect(); let mut y = String::new(); std::io::stdin().read_line(&mut y).ok(); let y: Vec = y.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let mut m = String::new(); std::io::stdin().read_line(&mut m).ok(); let m: Vec = m.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let mut paths = vec![vec![]; n]; for i in 0..v { paths[s[i]].push((t[i], y[i], m[i])); } let mut dp = vec![vec![INF; c+1]; n]; dp[0][0] = 0; let mut deque = VecDeque::new(); deque.push_back((0, 0, 0)); while let Some((pos, cost, time)) = deque.pop_front() { if dp[pos][cost] < time { continue; } for &(npos, addcost, addtime) in paths[pos].iter() { let ncost = cost + addcost; let ntime = time + addtime; if ncost > c || dp[npos][ncost] <= ntime { continue; } dp[npos][ncost] = ntime; deque.push_back((npos, ncost, ntime)); } } let minval = *dp[n-1].iter().min().unwrap(); if minval == INF { println!("-1"); } else { println!("{}", minval); } }