use std::collections::VecDeque; 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 u = temp[0]-1; let v = temp[1]-1; paths[u].push(v); paths[v].push(u); } let mut q = String::new(); std::io::stdin().read_line(&mut q).ok(); let q: usize = q.trim().parse().unwrap(); let queries = (0..q).map(|_| { let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); let temp: usize = temp.trim().parse().unwrap(); temp-1 }) .collect::>(); for &i in queries.iter() { let mut checked = vec![false; n]; checked[i] = true; let mut dist = 0usize; let mut deque = VecDeque::new(); deque.push_back(i); loop { let limit = deque.len(); for _ in 0..limit { let u = deque.pop_front().unwrap(); for &v in paths[u].iter() { if checked[v] { continue; } checked[v] = true; deque.push_back(v); } } if deque.is_empty() { break; } dist += 1; } println!("{} {}", checked.iter().filter(|&&v| v).count() - 1, (dist as f64).log2().ceil() as usize); } }