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