#![allow(dead_code, unused_imports, unused_macros)] use std::{ cell::UnsafeCell, cmp::{max, min}, collections::{HashMap, VecDeque}, io::{BufWriter, Read, Stdin, Stdout, Write}, mem::swap, str::FromStr, }; use disjoint_set::DisjointSet; mod disjoint_set { pub struct DisjointSet { parent: Vec, size: Vec, } impl DisjointSet { pub fn new(n: usize) -> DisjointSet { DisjointSet { parent: (0..n).collect(), size: vec![1; n], } } fn root(&mut self, x: usize) -> usize { if x == self.parent[x] { x } else { let tmp = self.parent[x]; self.parent[x] = self.root(tmp); self.parent[x] } } pub fn merge(&mut self, x: usize, y: usize) { let x = self.root(x); let y = self.root(y); if x == y { return; } if self.size[x] > self.size[y] { self.size[x] += self.size[y]; self.parent[y] = x; } else { self.size[y] += self.size[x]; self.parent[x] = y; } } pub fn same(&mut self, x: usize, y: usize) -> bool { self.root(x) == self.root(y) } pub fn size(&mut self, x: usize) -> usize { let x = self.root(x); self.size[x] } } } fn main() { let n = read!(usize); let m = read!(usize); let mut uf = DisjointSet::new(n * 2); for _ in 0..m { let a = read!(usize); let b = read!(usize); uf.merge(a - 1, b - 1); } if !uf.same(0, n) && m >= n { println!("Yes") } else { println!("No") } out_flush(); } const IO_BUF_SIZE: usize = 1 << 16; type Input = Scanner; type Output = BufWriter; fn _init_input() -> Input { Scanner::new(std::io::stdin()) } fn _init_output() -> Output { BufWriter::with_capacity(IO_BUF_SIZE, std::io::stdout()) } #[repr(transparent)] struct Unsync(T); unsafe impl Sync for Unsync {} type BadLazy = Unsync>>; impl BadLazy { const fn new() -> Self { Self(UnsafeCell::new(None)) } } static INPUT: BadLazy = BadLazy::new(); static OUTPUT: BadLazy = BadLazy::new(); fn inp R, R>(f: F) -> R { unsafe { f((&mut *INPUT.0.get()).get_or_insert_with(_init_input)) } } fn out R, R>(f: F) -> R { unsafe { f((&mut *OUTPUT.0.get()).get_or_insert_with(_init_output)) } } #[macro_export] macro_rules! read { () => { read() }; ($t: ty) => { read::<$t>() }; ($t: ty, $($tt: ty),*) => { (read::<$t>(), $(read::<$tt>(),)*) }; [$t: ty; $n: expr] => { read_vec::<$t>($n) }; } #[macro_export] macro_rules! println { () => { out(|x| { let _ = writeln!(x); }) }; ($exp: expr) => { out(|x| { let _ = writeln!(x, "{}", $exp); }) }; ($fmt: expr, $($arg : tt )*) => { out(|x| { let _ = writeln!(x, $fmt, $($arg)*); }) } } #[macro_export] macro_rules! print { ($exp: expr) => { out(|x| { let _ = write!(x, "{}", $exp); }) }; ($fmt: expr, $($arg : tt )*) => { out(|x| { let _ = write!(x, $fmt, $($arg)*); }) } } fn out_flush() { out(|x| { let _ = x.flush(); }); } fn input_is_eof() -> bool { inp(|x| x.eof()) } fn read_byte() -> u8 { inp(|x| x.byte()) } fn read_bytes_no_skip(n: usize) -> Vec { inp(|x| x.bytes_no_skip(n)) } fn read_bytes(n: usize) -> Vec { inp(|x| x.bytes(n)) } fn read_bytes2(n: usize, m: usize) -> Vec> { inp(|x| x.bytes2(n, m)) } fn read_token() -> Vec { inp(|x| x.token_bytes()) } fn read_token_str() -> String { unsafe { String::from_utf8_unchecked(read_token()) } } fn read_line() -> Vec { inp(|x| x.line_bytes()) } fn read_line_str() -> String { unsafe { String::from_utf8_unchecked(read_line()) } } fn read() -> T { read_token_str().parse::().ok().expect("failed parse") } fn read_vec(n: usize) -> Vec { (0..n).map(|_| read()).collect() } fn read_vec2(n: usize, m: usize) -> Vec> { (0..n).map(|_| read_vec(m)).collect() } struct Scanner { src: R, _buf: Vec, _pt: usize, // pointer _rd: usize, // bytes read } impl Scanner { fn new(src: R) -> Scanner { Scanner { src, _buf: vec![0; IO_BUF_SIZE], _pt: 1, _rd: 1, } } fn _check_buf(&mut self) { if self._pt == self._rd { self._rd = self.src.read(&mut self._buf).unwrap_or(0); self._pt = (self._rd == 0) as usize; } } // returns true if end of file fn eof(&mut self) -> bool { self._check_buf(); self._rd == 0 } // filters \r, returns \0 if eof fn byte(&mut self) -> u8 { loop { self._check_buf(); if self._rd == 0 { return 0; } let res = self._buf[self._pt]; self._pt += 1; if res != b'\r' { return res; } } } fn bytes_no_skip(&mut self, n: usize) -> Vec { (0..n).map(|_| self.byte()).collect() } fn bytes(&mut self, n: usize) -> Vec { let res = self.bytes_no_skip(n); self.byte(); res } fn bytes2(&mut self, n: usize, m: usize) -> Vec> { (0..n).map(|_| self.bytes(m)).collect() } fn token_bytes(&mut self) -> Vec { let mut res = Vec::new(); let mut c = self.byte(); while c <= b' ' { if c == b'\0' { return res; } c = self.byte(); } loop { res.push(c); c = self.byte(); if c <= b' ' { return res; } } } fn line_bytes(&mut self) -> Vec { let mut res = Vec::new(); let mut c = self.byte(); while c != b'\n' && c != b'\0' { res.push(c); c = self.byte(); } res } }