use std::collections::VecDeque; const INF: usize = 1usize << 60; fn main() { let mut nmk = String::new(); std::io::stdin().read_line(&mut nmk).ok(); let nmk: Vec = nmk.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let n = nmk[0]; let m = nmk[1]; let k = nmk[2]; let mut paths = vec![vec![]; n]; for _ in 0..m { let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); let temp: Vec = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let u = temp[0]-1; let v = temp[1]-1; let c = temp[2]; paths[u].push((v, c)); paths[v].push((u, c)); } let mut lower = 0usize; let mut upper = INF; while upper > lower { let middle = (upper + lower) / 2; let mut dists = vec![INF; n]; dists[0] = 0; let mut deque = VecDeque::new(); deque.push_back(0); while let Some(u) = deque.pop_front() { for &(v, c) in paths[u].iter() { let ncost = dists[u] + if c > middle { 1 } else { 0 }; if ncost >= dists[v] { continue; } dists[v] = ncost; if c > middle { deque.push_back(v); } else { deque.push_front(v); } } } if dists[n-1] < k { upper = middle; } else { lower = middle + 1; } } println!("{}", upper); }