use std::collections::VecDeque; use proconio::{input, marker::Usize1}; fn main() { input! { n:usize, m:usize, uv:[(Usize1,Usize1);m], } let mut g = vec![vec![]; n]; for &(u, v) in uv.iter() { g[u].push(v); g[v].push(u); } if g[0].is_empty() { for _ in 0..n { println!("0"); } return; } let mut q = VecDeque::new(); let mut dists = vec![n + 1; n]; dists[0] = 0; q.push_back(0); while let Some(crr) = q.pop_front() { for &nxt in g[crr].iter() { if dists[nxt] != n + 1 { continue; } dists[nxt] = dists[crr] + 1; q.push_back(nxt); } } dists[0] = 2; let mut ans = vec![0; n]; let mut add_odd = 0; let mut add_even = 0; dists.sort(); let mut ind = 0; for i in 1..=n { while ind < n && dists[ind] == i { if i % 2 == 0 { add_even += 1; } else { add_odd += 1; } ind += 1; } ans[i - 1] = if i % 2 == 0 { add_even } else { add_odd }; } for i in 0..n { println!("{}", ans[i]); } }