fn main() { proconio::input! { n: usize, m: usize, ab: [(usize, usize); m], } let graph = { let mut g = vec![vec![]; n]; for (a, b) in ab { g[a - 1].push(b - 1); g[b - 1].push(a - 1); } g }; if is_possible(&graph) { println!("YES"); } else { println!("NO"); } } fn is_possible(graph: &Vec>) -> bool { let nodes = { let mut nodes = vec![vec![]; graph.len()]; for &ni in &graph[0] { for &nj in &graph[ni] { if nj != 0 { nodes[nj].push(ni); } } } nodes }; for ni in 0..graph.len() { for &nj in &graph[ni] { if nodes[ni].len() == 0 || nodes[nj].len() == 0 { continue; } if nodes[ni].len().min(nodes[nj].len()) >= 3 { return true; } for &nk in &nodes[ni] { if nk != nj { for &nl in &nodes[nj] { if nl != ni && nl != nk { return true; } } } } } } false }