use std::collections::{HashSet, BTreeSet, HashMap}; struct UnionFind { n: usize, parents: Vec, depths: Vec, chains: Vec, } impl UnionFind { fn new(n: usize) -> Self { UnionFind { n: n, parents: (0..n).collect(), depths: vec![0; n], chains: vec![1; n], } } 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 x = self.parents[a]; let y = self.parents[b]; if self.depths[x] > self.depths[y] { self.parents[x] = self.parents[y]; self.chains[y] += self.chains[x]; } else { self.parents[y] = self.parents[x]; self.chains[x] += self.chains[y]; if self.depths[x] == self.depths[y] { self.depths[x] += 1; } } } 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 chain_cnt(&mut self, i: usize) -> usize { let idx = self.find(i); self.chains[idx] } } 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 btree = BTreeSet::new(); let mut lines = Vec::with_capacity(m); 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 a = temp[0]; let b = temp[1]; lines.push((a, b)); btree.insert(a); btree.insert(b); } let mapping = btree.iter().enumerate().map(|(i, &v)| (v, i)).collect::>(); let mut uf = UnionFind::new(btree.len()); let mut paths = vec![vec![]; btree.len()]; for &(l, r) in lines.iter() { let l = *mapping.get(&l).unwrap(); let r = *mapping.get(&r).unwrap(); paths[l].push(r); paths[r].push(l); uf.unite(l, r); } if (0..btree.len()).map(|i| uf.find(i)).collect::>().len() > 1 { println!("NO"); return; } let cnt = paths.iter().filter(|&v| v.len() % 2 == 1).count(); if cnt > 2 { println!("NO"); } else { println!("YES"); } }