#![allow(unused_macros, unused_imports)] use std::io::*; use std::collections::*; fn read_line() -> String { let mut s = String::new(); stdin().read_line(&mut s).unwrap(); s } macro_rules! from_iter { ($($a:ident),+ = $it:expr) => { $(let $a;)+ { let mut _it = $it.into_iter(); $($a = _it.next().unwrap();)+ assert!(_it.next().is_none()); } }; } macro_rules! from_str { ($($a:ident : $t:ty),+ = $s:expr) => { $(let $a: $t;)+ { let mut _it = $s.split_whitespace(); $($a = _it.next().unwrap().parse().unwrap();)+ assert!(_it.next().is_none()); } }; } macro_rules! print_var_fmt { ($e:expr) => { concat!(stringify!($e), ":\t{}") }; ($e:expr, $($es: expr),+) => { concat!(print_var_fmt!($e), ",\t", print_var_fmt!($($es),+)) }; } macro_rules! dbg { ($($es:expr),+) => { writeln!(&mut io::stderr(), print_var_fmt!($($es),*), $($es),*); }; } fn main() { let line = read_line(); from_str!(n: usize, m: usize = line.trim()); let mut boss: Vec = (0..n as u32+1).collect(); let mut piki: Vec = vec![1; n+1]; for _ in 0..m { let line = read_line(); from_str!(a: usize, b: usize = line.trim()); let ta = boss[a] as usize; let tb = boss[b] as usize; if ta != tb { if piki[ta] > piki[tb] || piki[ta] == piki[tb] && ta < tb { piki[ta] += piki[tb]; for i in 1..n+1 { if boss[i] == tb as u32 { boss[i] = ta as u32; } } } else { piki[tb] += piki[ta]; for i in 1..n+1 { if boss[i] == ta as u32 { boss[i] = tb as u32; } } } } } for i in 1..n+1 { println!("{}", boss[i]); } }