#![allow(non_snake_case)] use std::collections::BinaryHeap; use proconio::{input}; fn main() { input!{ n: usize, m: usize, x: u64, es: [(usize, usize, u64, u64); m] } let mut adj = vec![Vec::new(); n]; for (u, v, c, t) in es { adj[u - 1].push((v - 1, c + t * x)); adj[v - 1].push((u - 1, c + t * x)); } let mut dist = vec![u64::MAX; n]; dist[0] = 0; let mut pq = BinaryHeap::new(); pq.push((0, 0)); while let Some((d, u)) = pq.pop() { if (-d) as u64 > dist[u] { continue; } for (v, c) in &adj[u] { let d1 = (-d) as u64 + c; if d1 < dist[*v] { dist[*v] = d1; pq.push((-(d1 as i64), *v)); } } } if dist[n - 1] == u64::MAX { println!("-1"); } else { println!("{}", (dist[n - 1] + x - 1) / x); } }