//use proconio::input; fn main() { let t = std::io::stdin(); let mut read = snio::Reader::new(t.lock()); let n = read.usize(); let m = read.usize(); let road_and_dist:Vec<(usize,usize,usize)> = (0..m).map(|_| (read.usize(),read.usize(), read.usize())).collect(); let mut g = vec![Vec::new();n]; let mut debu:Vec = vec![0;n]; for (s,t,u) in road_and_dist { g[s - 1].push((t - 1,u)); g[t - 1].push((s - 1,u)); } let t = binary_search(&g,&debu); println!("{} {}",t,dijkstra(&g,t,0)); } fn binary_search(g:&Vec>,debu:&Vec) -> usize { let (mut lb , mut ub) = (0,1e9 as usize + 1); while ub - lb > 1 { let mid = (ub + lb) / 2; if dijkstra(g,mid,0) != 1e18 as usize{ lb = mid; } else { ub = mid; } } lb } use std::collections::BinaryHeap; use std::cmp::Reverse; fn dijkstra(g:& Vec>,debu:usize,start:usize) -> usize{ let mut pq = BinaryHeap::new(); let mut dist = vec![1e18 as usize;g.len()]; pq.push(Reverse((0,start))); dist[start] = 0; while let Some(v) = pq.pop() { let (cost,now) = v.0; for (to,c) in &g[now] { if dist[now] < cost || *c < debu{ continue; } if dist[*to] > 1 + dist[now] { dist[*to] = dist[now] + 1; pq.push(Reverse((dist[*to],*to))); } } } //println!("{}",dist[g.len() - 1]); dist[g.len() - 1] } #[allow(dead_code)] pub mod snio { pub struct Reader { reader: R, buf: std::collections::VecDeque, } impl Reader { pub fn new(reader: R) -> Self { Self { reader, buf: std::collections::VecDeque::new(), } } fn load(&mut self) { while self.buf.is_empty() { let mut s = String::new(); let length = self.reader.read_line(&mut s).unwrap(); if length == 0 { break; } self.buf.extend(s.split_whitespace().map(|s| s.to_owned())); } } pub fn string(&mut self) -> String { self.load(); self.buf.pop_front().unwrap_or_else(|| panic!("input ended")) } pub fn char(&mut self) -> char { let string = self.string(); let mut chars = string.chars(); let res = chars.next().unwrap(); assert!(chars.next().is_none(), "invalid input!"); res } pub fn chars(&mut self) -> Vec { self.read::().chars().collect() } pub fn read(&mut self) -> T where ::Err: ::std::fmt::Debug, { self.string().parse::().expect("Failed to parse the input.") } } macro_rules! definition_of_reader_of_numbers { ($($ty:tt,)*) => { impl Reader { $( #[inline] pub fn $ty (&mut self) -> $ty { self.read::<$ty>() } )* } } } definition_of_reader_of_numbers! { u8,u16,u32,u64,usize, i8,i16,i32,i64,isize, } }