use proconio::{input, marker::Usize1}; use std::collections::BinaryHeap; fn main() { input! { n: usize, m: usize, p: usize, y: usize, abc: [(Usize1, Usize1, usize); m], de: [(Usize1, usize); p], } let mut graph = vec![vec![]; n]; for (a, b, c) in abc { graph[a].push((b, c)); graph[b].push((a, c)) } let mut rest_money = vec![0; n]; rest_money[0] = y; let mut heap = BinaryHeap::new(); heap.push((y, 0)); while let Some((money, pos)) = heap.pop() { if rest_money[pos] > money { continue; } for &(next, robbed) in &graph[pos] { let new_money = (money - robbed).max(0); if new_money == 0 || rest_money[next] >= new_money { continue; } rest_money[next] = new_money; heap.push((rest_money[next], next)); } } let mut ans = 0; for (d, e) in de { ans = ans.max(rest_money[d] / e); } println!("{}", ans); }