// use std::ops::{Index, IndexMut}; // use std::cmp::{Ordering, min, max}; // use std::collections::{BinaryHeap, BTreeMap}; // use std::collections::btree_map::Entry::{Occupied, Vacant}; // use std::clone::Clone; fn getline() -> String{ let mut res = String::new(); std::io::stdin().read_line(&mut res).ok(); res } macro_rules! readl { ($t: ty) => { { let s = getline(); s.trim().parse::<$t>().unwrap() } }; ($( $t: ty),+ ) => { { let s = getline(); let mut iter = s.trim().split(' '); ($(iter.next().unwrap().parse::<$t>().unwrap(),)*) } }; } macro_rules! readlvec { ($t: ty) => { { let s = getline(); let iter = s.trim().split(' '); iter.map(|x| x.parse().unwrap()).collect::>() } } } macro_rules! mvec { ($v: expr, $s: expr) => { vec![$v; $s] }; ($v: expr, $s: expr, $($t: expr),*) => { vec![mvec!($v, $($t),*); $s] }; } macro_rules! debug { ($x: expr) => { println!("{}: {:?}", stringify!($x), $x) } } fn printiter<'a, T>(v: &'a T) where &'a T: std::iter::IntoIterator, <&'a T as std::iter::IntoIterator>::Item: std::fmt::Display { for (i,e) in v.into_iter().enumerate() { if i != 0 { print!(" "); } print!("{}", e); } println!(""); } type Cost = i64; #[derive(Clone)] struct Edge { to: usize, cost: Cost, } impl Ord for Edge { fn cmp(&self, other: &Edge) -> std::cmp::Ordering { (-self.cost).cmp(&(-other.cost)) } } impl PartialOrd for Edge { fn partial_cmp(&self, other: &Edge) -> Option { Some(self.cmp(other)) } } impl Eq for Edge {} impl PartialEq for Edge { fn eq(&self, other: &Edge) -> bool { self.cost == other.cost } } #[derive(Clone)] struct Graph { adj: Vec>, } impl std::ops::Index for Graph { type Output = Vec; fn index(&self, i: usize) -> &Vec { &self.adj[i] } } impl std::ops::IndexMut for Graph { fn index_mut<'a>(&'a mut self, i: usize) -> &'a mut Vec { &mut self.adj[i] } } impl Graph { fn new(n: usize) -> Graph{ Graph { adj: vec![vec![]; n], } } fn size(&self) -> usize{ self.adj.capacity() } fn add_edge(&mut self, from: usize, to_: usize, cost_: Cost) { self.adj[from].push(Edge{to: to_, cost: cost_}); } fn add_uedge(&mut self, from: usize, to_: usize, cost_: Cost) { self.add_edge(from, to_, cost_); self.add_edge(to_, from, cost_); } } use std::collections::HashSet; fn main() { let (n, m) = readl!(usize, usize); let g = { let mut g = Graph::new(n); for _ in 0..m { let (a, b) = readl!(usize, usize); g.add_uedge(a-1, b-1, -1); } g }; let mut pa = vec![HashSet::new(); n]; for e1 in &g[0] { for e2 in &g[e1.to] { if e2.to != 0 { pa[e2.to].insert(e1.to); } } } // let pa: Vec> = pa.into_iter().map(|s| { // s.into_iter().collect() // }).collect(); // debug!(pa); let mut f = false; for p in 0..n { for e in &g[p] { if pa[p].len() == 0 || pa[e.to].len() == 0 { continue; } if pa[p].len() < 3 && pa[e.to].len() < 3 { for ee in &pa[p] { if *ee == e.to { continue; } for eee in &pa[e.to] { if *eee == p { continue; } if *ee != *eee { f = true; } } } } else { f = true; } } } if f { println!("YES"); } else { println!("NO"); } }