use std::{cmp::Reverse, collections::BinaryHeap}; const INF: usize = 1usize << 60; #[derive(Debug, Clone)] struct Dijkstra { n: usize, pathcosts: Vec>, pathcostsrev: Vec>, costs: Vec } impl Dijkstra { fn new(n: usize) -> Self { Self { n: n , pathcosts: vec![vec![]; n] , pathcostsrev: vec![vec![]; n] , costs: vec![INF; n] } } fn pusha2b(&mut self, a: usize, b: usize, cost: usize) { self.pathcosts[a].push((cost, b)); self.pathcostsrev[b].push((cost, a)); } fn get_cost(&self, idx: usize) -> usize { self.costs[idx] } fn solve(&mut self, startpoint: usize) { let mut que = BinaryHeap::new(); que.push(Reverse((0, startpoint))); self.costs[startpoint] = 0; while let Some(Reverse(p)) = que.pop() { let cost = p.0; let dest = p.1; if cost > self.costs[dest] { continue; } for &p2 in self.pathcosts[dest].iter() { if self.costs[dest] + p2.0 < self.costs[p2.1] { self.costs[p2.1] = self.costs[dest] + p2.0; que.push(Reverse((self.costs[p2.1], p2.1))); } } } } fn reconstruct(&self, startpoint: usize, endpoint: usize) -> Vec<(usize, usize)> { let mut ret = vec![]; if self.costs[endpoint] == INF { return ret; } let mut current = endpoint; while current != startpoint { for &(cost, u) in self.pathcostsrev[current].iter() { if self.costs[current] == self.costs[u] + cost { let prev = current; current = u; ret.push((current, prev)); break; } } } ret.reverse(); ret } } 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::with_capacity(m); 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.push((u, v, c)); } let mut lower = 0usize; let mut upper = 200001; while upper > lower { let middle = (upper + lower) / 2; let mut dijkstra = Dijkstra::new(n); for &(u, v, c) in paths.iter() { dijkstra.pusha2b(u, v, if c > middle { 1 } else { 0 }); dijkstra.pusha2b(v, u, if c > middle { 1 } else { 0 }); } dijkstra.solve(0); if dijkstra.costs[n-1] < k { upper = middle; } else { lower = middle + 1; } } println!("{}", upper); }