use std::collections::VecDeque; const INF: usize = 1usize << 60; struct UnionFind { n: usize, parents: Vec, } impl UnionFind { fn new(n: usize) -> Self { UnionFind { n: n, parents: (0..n).collect(), } } fn equiv(&mut self, a: usize, b: usize) -> bool { self.find(a) == self.find(b) } fn unite(&mut self, a: usize, b: usize) { if self.equiv(a, b) { return; } let (a, b) = (a.min(b), a.max(b)); let x = self.parents[a]; let y = self.parents[b]; self.parents[y] = self.parents[x]; } fn find(&mut self, a: usize) -> usize { if self.parents[a] == a { return a; } let p = self.find(self.parents[a]); self.parents[a] = p; p } } 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]; let mut uf = UnionFind::new(n); let mut size = vec![1usize; 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 p = temp[0]-1; let q = temp[1]-1; paths[p].push(q); paths[q].push(p); let pu = uf.find(p); let pv = uf.find(q); if pu == pv { continue; } uf.unite(pu, pv); let p = uf.find(pu); if p == pu { size[pu] += size[pv]; size[pv] = 0; } else { size[pv] += size[pu]; size[pu] = 0; } } let mut q = String::new(); std::io::stdin().read_line(&mut q).ok(); let q: usize = q.trim().parse().unwrap(); let a = (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 &u in a.iter() { let size = size[uf.find(u)]-1; let mut dists = vec![INF; n]; dists[u] = 0; let mut deque = VecDeque::new(); deque.push_back(u); while let Some(x) = deque.pop_front() { for &v in paths[x].iter() { if dists[v] < INF { continue; } dists[v] = dists[x] + 1; deque.push_back(v); } } println!("{} {}", size, (*dists.iter().filter(|&&v| v > 0 && v < INF).max().unwrap_or(&0usize) as f64).log2().ceil() as usize); } }